Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line | 
|---|---|---|---|
| 259 | f9daq | 1 | #include <utility.h> | 
        
| 2 | #include <rs232.h> | 
        ||
| 3 | #include <ansi_c.h> | 
        ||
| 4 | #include <cvirte.h>              | 
        ||
| 5 | #include <userint.h> | 
        ||
| 6 | #include <hm7044.h>           | 
        ||
| 7 | |||
| 8 | |||
| 9 | |||
| 10 | /* | 
        ||
| 11 | linuxs | 
        ||
| 12 | root: trenutna konfiguracija | 
        ||
| 13 | |||
| 14 |  setserial -G /dev/ttyS0 | 
        ||
| 15 | root: nastavitev konfiguracij | 
        ||
| 16 | # setserial /dev/ttyS0  baud_base 9600 spd_normal skip_test | 
        ||
| 17 |  stty 9600 cs8 -parenb -cstopb crtscts -echo -F /dev/ttyS0 | 
        ||
| 18 | */ | 
        ||
| 19 | |||
| 20 | |||
| 21 | char gresult[MAX_CMD] ;  | 
        ||
| 22 | static int comport=1 ;  | 
        ||
| 23 | |||
| 24 | |||
| 25 | |||
| 26 | int HM7044_Open(int port){  | 
        ||
| 27 | int rs232er;  | 
        ||
| 28 | |||
| 29 | comport=port;  | 
        ||
| 30 | rs232er = OpenComConfig (comport, "", 9600, 0, 8, 1, 512, 512);  | 
        ||
| 31 | return rs232er;  | 
        ||
| 32 | } | 
        ||
| 33 | |||
| 34 | int HM7044_Close(void){  | 
        ||
| 35 | int rs232er;  | 
        ||
| 36 | rs232er = CloseCom(comport);  | 
        ||
| 37 | return rs232er;  | 
        ||
| 38 | } | 
        ||
| 39 | |||
| 40 | |||
| 41 | |||
| 42 | |||
| 43 | static int com_send ( char* cmd ) {  | 
        ||
| 44 | char str1[1024] ;  | 
        ||
| 45 | int err;  | 
        ||
| 46 | sprintf ( str1, "%s\r", cmd ) ;  | 
        ||
| 47 | |||
| 48 | err = ComWrt (comport, str1, strlen(str1));  | 
        ||
| 49 | fprintf ( stdout, "Command: %s \t", cmd ) ;  | 
        ||
| 50 |   //printf("%d bytes written: %s\n",err,str1); | 
        ||
| 51 | return err;  | 
        ||
| 52 | |||
| 53 | } | 
        ||
| 54 | |||
| 55 | static int com_read ( char* result ) {  | 
        ||
| 56 | int err;  | 
        ||
| 57 | int nbytes=1024;  | 
        ||
| 58 | int maxsize=nbytes;  | 
        ||
| 59 | result[0]=0;  | 
        ||
| 60 | err = ComRdTerm (comport, result, nbytes,13);  | 
        ||
| 61 |    //CR=13 | 
        ||
| 62 | if (err>0 && err>=maxsize) result[maxsize-1]=0;  | 
        ||
| 63 | if (err>0 && err<maxsize) result[err]=0;  | 
        ||
| 64 |    //printf("%d bytes read=> #%s#\n\t",err,result); | 
        ||
| 65 | return err;  | 
        ||
| 66 | |||
| 67 | |||
| 68 | } | 
        ||
| 69 | |||
| 70 | |||
| 71 | int HM7044_SendCmd ( char* cmd, char* result )  | 
        ||
| 72 | { | 
        ||
| 73 | com_send ( cmd ) ;  | 
        ||
| 74 | if ( com_read ( result ) ) {  | 
        ||
| 75 | printf ( "answer: %s\n", result ) ;  | 
        ||
| 76 | return 0 ;  | 
        ||
| 77 |   } | 
        ||
| 78 | else {  | 
        ||
| 79 | printf ( "\nanswer: error\n" ) ;  | 
        ||
| 80 | return 1 ;  | 
        ||
| 81 |   } | 
        ||
| 82 | }   | 
        ||
| 83 | |||
| 84 | |||
| 85 | static int send_int( char* cmd,int val, char* result ) {  | 
        ||
| 86 | char cmd1[MAX_CMD];  | 
        ||
| 87 | sprintf(cmd1,"%s %d",cmd,val);  | 
        ||
| 88 | return HM7044_SendCmd(cmd1,result);  | 
        ||
| 89 | } | 
        ||
| 90 | |||
| 91 | static int send_float( char* cmd,float val, char* result ) {  | 
        ||
| 92 | char cmd1[MAX_CMD];  | 
        ||
| 93 | sprintf(cmd1,"%s %f",cmd,val);  | 
        ||
| 94 | return HM7044_SendCmd(cmd1,result);  | 
        ||
| 95 | } | 
        ||
| 96 | |||
| 97 | int HM7044_SetVoltage(int ch, float value){  | 
        ||
| 98 | char cmd[MAX_CMD];  | 
        ||
| 99 | send_int("SEL",ch, gresult);  | 
        ||
| 100 | |||
| 101 | sprintf(cmd,"SET %4.2f V",value);  | 
        ||
| 102 | HM7044_SendCmd(cmd, gresult);  | 
        ||
| 103 | |||
| 104 | HM7044_SendCmd("SEL NONE", gresult);  | 
        ||
| 105 | return 0;  | 
        ||
| 106 | |||
| 107 | } | 
        ||
| 108 | |||
| 109 | int HM7044_SetCurrent(int ch, float value){  | 
        ||
| 110 | char cmd[MAX_CMD];  | 
        ||
| 111 | send_int("SEL",ch, gresult);  | 
        ||
| 112 | |||
| 113 | sprintf(cmd,"SET %f A",value);  | 
        ||
| 114 | HM7044_SendCmd(cmd, gresult);  | 
        ||
| 115 | HM7044_SendCmd("SEL NONE", gresult);  | 
        ||
| 116 | return 0;  | 
        ||
| 117 | } | 
        ||
| 118 | |||
| 119 | |||
| 120 | int HM7044_Read( float *data){  | 
        ||
| 121 | int nb,i;  | 
        ||
| 122 | com_send("READ");  | 
        ||
| 123 | printf ( "\n");  | 
        ||
| 124 | for (i=0;i<3;i++){  | 
        ||
| 125 | com_read ( gresult );  | 
        ||
| 126 | printf ( "%d.answer: %s\n",i, gresult ) ;  | 
        ||
| 127 |    } | 
        ||
| 128 | |||
| 129 | nb = sscanf (gresult, "%fV%fV%fV%fV",  | 
        ||
| 130 | &data[0],&data[1],&data[2],&data[3]);  | 
        ||
| 131 | for (i=0;i<nb;i++){  | 
        ||
| 132 | |||
| 133 |       //printf("%d. %f\n",i, data[i]); | 
        ||
| 134 | |||
| 135 |    } | 
        ||
| 136 | return (nb==4);  | 
        ||
| 137 | |||
| 138 | } | 
        ||
| 139 | |||
| 140 | int HM7044_Enable_Output(int ch){  | 
        ||
| 141 | send_int("SEL",ch, gresult);  | 
        ||
| 142 | HM7044_SendCmd("EN", gresult);  | 
        ||
| 143 | HM7044_SendCmd("SEL NONE", gresult);  | 
        ||
| 144 | return 0;  | 
        ||
| 145 | } | 
        ||
| 146 | |||
| 147 | int HM7044_Disable_Output(int ch){  | 
        ||
| 148 | send_int("SEL",ch, gresult);  | 
        ||
| 149 | HM7044_SendCmd("DIS", gresult);  | 
        ||
| 150 | HM7044_SendCmd("SEL NONE", gresult);  | 
        ||
| 151 | return 0;  | 
        ||
| 152 | } | 
        ||
| 153 | |||
| 154 | int HM7044_SwitchOn(int ch){  | 
        ||
| 155 | send_int("SEL",ch, gresult);  | 
        ||
| 156 | HM7044_SendCmd("ON", gresult);  | 
        ||
| 157 | HM7044_SendCmd("SEL NONE", gresult);  | 
        ||
| 158 | return 0;  | 
        ||
| 159 | } | 
        ||
| 160 | |||
| 161 | |||
| 162 | int HM7044_SwitchOff(int ch){  | 
        ||
| 163 | send_int("SEL",ch, gresult);  | 
        ||
| 164 | HM7044_SendCmd("ON", gresult);  | 
        ||
| 165 | HM7044_SendCmd("SEL NONE", gresult);  | 
        ||
| 166 | return 0;  | 
        ||
| 167 | } | 
        ||
| 168 | |||
| 169 | int HM7044_FuseOff(int ch){  | 
        ||
| 170 | send_int("SEL",ch, gresult);  | 
        ||
| 171 | HM7044_SendCmd("FUSE OFF", gresult);  | 
        ||
| 172 | HM7044_SendCmd("SEL NONE", gresult);  | 
        ||
| 173 | return 0;  | 
        ||
| 174 | } | 
        ||
| 175 | |||
| 176 | |||
| 177 | int HM7044_FuseOn(int ch){  | 
        ||
| 178 | send_int("SEL",ch, gresult);  | 
        ||
| 179 | HM7044_SendCmd("FUSE ON", gresult);  | 
        ||
| 180 | HM7044_SendCmd("SEL NONE", gresult);  | 
        ||
| 181 | return 0;  | 
        ||
| 182 | } | 
        ||
| 183 |