#include <utility.h>
#include <rs232.h>
#include <ansi_c.h>
#include <cvirte.h>
#include <userint.h>
#include <hm7044.h>
/*
linuxs
root: trenutna konfiguracija
setserial -G /dev/ttyS0
root: nastavitev konfiguracij
# setserial /dev/ttyS0 baud_base 9600 spd_normal skip_test
stty 9600 cs8 -parenb -cstopb crtscts -echo -F /dev/ttyS0
*/
char gresult[MAX_CMD] ;
static int comport=1 ;
int HM7044_Open(int port){
int rs232er;
comport=port;
rs232er = OpenComConfig (comport, "", 9600, 0, 8, 1, 512, 512);
return rs232er;
}
int HM7044_Close(void){
int rs232er;
rs232er = CloseCom(comport);
return rs232er;
}
static int com_send ( char* cmd ) {
char str1[1024] ;
int err;
err
= ComWrt
(comport
, str1
, strlen(str1
));
fprintf ( stdout
, "Command: %s \t", cmd
) ;
//printf("%d bytes written: %s\n",err,str1);
return err;
}
static int com_read ( char* result ) {
int err;
int nbytes=1024;
int maxsize=nbytes;
result[0]=0;
err = ComRdTerm (comport, result, nbytes,13);
//CR=13
if (err>0 && err>=maxsize) result[maxsize-1]=0;
if (err>0 && err<maxsize) result[err]=0;
//printf("%d bytes read=> #%s#\n\t",err,result);
return err;
}
int HM7044_SendCmd ( char* cmd, char* result )
{
com_send ( cmd ) ;
if ( com_read ( result ) ) {
printf ( "answer: %s\n", result
) ;
return 0 ;
}
else {
printf ( "\nanswer: error\n" ) ;
return 1 ;
}
}
static int send_int( char* cmd,int val, char* result ) {
char cmd1[MAX_CMD];
return HM7044_SendCmd(cmd1,result);
}
static int send_float( char* cmd,float val, char* result ) {
char cmd1[MAX_CMD];
return HM7044_SendCmd(cmd1,result);
}
int HM7044_SetVoltage(int ch, float value){
char cmd[MAX_CMD];
send_int("SEL",ch, gresult);
HM7044_SendCmd(cmd, gresult);
HM7044_SendCmd("SEL NONE", gresult);
return 0;
}
int HM7044_SetCurrent(int ch, float value){
char cmd[MAX_CMD];
send_int("SEL",ch, gresult);
HM7044_SendCmd(cmd, gresult);
HM7044_SendCmd("SEL NONE", gresult);
return 0;
}
int HM7044_Read( float *data){
int nb,i;
com_send("READ");
for (i=0;i<3;i++){
com_read ( gresult );
printf ( "%d.answer: %s\n",i
, gresult
) ;
}
nb
= sscanf (gresult
, "%fV%fV%fV%fV",
&data[0],&data[1],&data[2],&data[3]);
for (i=0;i<nb;i++){
//printf("%d. %f\n",i, data[i]);
}
return (nb==4);
}
int HM7044_Enable_Output(int ch){
send_int("SEL",ch, gresult);
HM7044_SendCmd("EN", gresult);
HM7044_SendCmd("SEL NONE", gresult);
return 0;
}
int HM7044_Disable_Output(int ch){
send_int("SEL",ch, gresult);
HM7044_SendCmd("DIS", gresult);
HM7044_SendCmd("SEL NONE", gresult);
return 0;
}
int HM7044_SwitchOn(int ch){
send_int("SEL",ch, gresult);
HM7044_SendCmd("ON", gresult);
HM7044_SendCmd("SEL NONE", gresult);
return 0;
}
int HM7044_SwitchOff(int ch){
send_int("SEL",ch, gresult);
HM7044_SendCmd("ON", gresult);
HM7044_SendCmd("SEL NONE", gresult);
return 0;
}
int HM7044_FuseOff(int ch){
send_int("SEL",ch, gresult);
HM7044_SendCmd("FUSE OFF", gresult);
HM7044_SendCmd("SEL NONE", gresult);
return 0;
}
int HM7044_FuseOn(int ch){
send_int("SEL",ch, gresult);
HM7044_SendCmd("FUSE ON", gresult);
HM7044_SendCmd("SEL NONE", gresult);
return 0;
}