diff options
author | Siddharth11235 | 2019-09-03 18:09:16 +0530 |
---|---|---|
committer | Siddharth11235 | 2019-09-03 18:09:16 +0530 |
commit | b4b6aa36e3486a3544acc52419149b5671f841e9 (patch) | |
tree | 66c1783158f23e6d21c77324156fc57e18d4ac67 /Modelica-Arduino-MDD_Arduino_Revised/Resources/src/cmd_digital.c | |
parent | f5266f634f4fb4fd39933a83551a01cf446256b8 (diff) | |
download | OpenModelica_HIL-b4b6aa36e3486a3544acc52419149b5671f841e9.tar.gz OpenModelica_HIL-b4b6aa36e3486a3544acc52419149b5671f841e9.tar.bz2 OpenModelica_HIL-b4b6aa36e3486a3544acc52419149b5671f841e9.zip |
Diffstat (limited to 'Modelica-Arduino-MDD_Arduino_Revised/Resources/src/cmd_digital.c')
-rwxr-xr-x | Modelica-Arduino-MDD_Arduino_Revised/Resources/src/cmd_digital.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/Modelica-Arduino-MDD_Arduino_Revised/Resources/src/cmd_digital.c b/Modelica-Arduino-MDD_Arduino_Revised/Resources/src/cmd_digital.c new file mode 100755 index 0000000..f19d23b --- /dev/null +++ b/Modelica-Arduino-MDD_Arduino_Revised/Resources/src/cmd_digital.c @@ -0,0 +1,63 @@ +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> /* memset */ +#include <stdio.h> +#include <stdlib.h> +#include "../Include/serial.h" +#include "../Include/digital.h" + +int cmd_digital_out(int h,int pin_no,int val) +{ + int wr; + char pin[6]="Da"; + char v[2],temp[2]; + sprintf(temp,"%c",pin_no+48); + strcat(pin,temp); + strcat(pin,"1"); + //printf("%s",pin); + wr=write_serial(h,pin,4); + if (val > 0.5) + val = 1; + else + val = 0; + + sprintf(v,"%d",val); + strcpy(pin,"Dw"); + strcat(pin,temp); + strcat(pin,v); + //printf("%s",pin); + wr=write_serial(h,pin,4); + return wr; +} + +int cmd_digital_in(int h,int pin_no) +{ + int value = 0; + char pin[6]="Da"; + char v1[2],v2[2]; + int wr1, wr2; + sprintf(v1,"%c",pin_no+48); + strcat(pin,v1); + strcat(pin,"0"); + //printf("%s\n",pin); + wr1=write_serial(h,pin,4); + + strcpy(pin,"Dr"); + sprintf(v2,"%c",pin_no+48); + strcat(pin,v2); + wr2=write_serial(1,pin,3); + //binary transfer + int stat; + int num_bytes[2]; + char st[10]; + stat=status_serial(h,num_bytes); + while(num_bytes[0]<1) + stat=status_serial(h,num_bytes); + char* temp; + int wr=read_serial(h,st,1); + value=strtod(st,&temp); + //printf("%d\n",value); + return value; +} |