/cvi/apps/TempCtrl/Arduino_UNO/Arduino_UNO.ino |
---|
0,0 → 1,86 |
#include <SPI.h> |
#include <Adafruit_MAX31865.h> |
#define RREF 430.0 |
#define RNOMINAL 100.0 |
Adafruit_MAX31865 max = Adafruit_MAX31865(10, 11, 12, 13); |
int pinOut1 = 2; |
int pinOut2 = 4; |
int state1; |
int state2; |
void setup() { |
pinMode(pinOut1,OUTPUT); |
pinMode(pinOut2,OUTPUT); |
digitalWrite(pinOut1, HIGH); |
digitalWrite(pinOut2, HIGH); |
Serial.begin(115200); |
//Serial.println("Temperature"); |
max.begin(MAX31865_4WIRE); |
} |
void loop() { |
char incomingByte; |
if (Serial.available() > 0) { |
// read the incoming byte: |
incomingByte = Serial.read(); |
// say what you got: |
if (incomingByte == 0){ |
digitalWrite(pinOut1, HIGH); |
digitalWrite(pinOut2, HIGH); |
//Serial.println("low"); |
} |
else { |
digitalWrite(pinOut1, LOW); |
digitalWrite(pinOut2, LOW); |
//Serial.println("High"); |
} |
} |
uint16_t rtd = max.readRTD(); |
float t = max.temperature(RNOMINAL, RREF); |
state1 = digitalRead(pinOut1); |
state2 = digitalRead(pinOut2); |
/* |
Serial.print("RTD value: "); Serial.println(rtd); |
float ratio = rtd; |
ratio /= 32768; |
Serial.print("Ratio = "); Serial.println(ratio,8); |
Serial.print("Resistance = "); Serial.println(RREF*ratio,8); |
Serial.print("Temperature = "); Serial.println(max.temperature(RNOMINAL, RREF)); |
// Preveri in vrne vrednost napak |
uint8_t fault = max.readFault(); |
if(fault) { |
Serial.print("Fault 0x"); Serial.println(fault, HEX); |
if (fault & MAX31865_FAULT_HIGHTHRESH) { |
Serial.println("RTD High Threshold"); |
} |
if (fault & MAX31865_FAULT_LOWTHRESH) { |
Serial.println("RTD Low Threshold"); |
} |
if (fault & MAX31865_FAULT_REFINHIGH) { |
Serial.println("REFIN- < 0.85 x Bias - FORCE- open"); |
} |
if (fault & MAX31865_FAULT_RTDINLOW) { |
Serial.println("RTDIN- < 0.85 x Bias - FORCE- open"); |
} |
if (fault & MAX31865_FAULT_OVUV) { |
Serial.println("Under/over voltage"); |
} |
max.clearFault(); |
} |
*/ |
Serial.print(t); |
Serial.print(" "); |
Serial.print(state1); |
Serial.print(" "); |
Serial.println(state2); |
//Serial.println(); |
delay(1000); |
} |
/cvi/apps/TempCtrl/TempCtrl.c |
---|
73,8 → 73,6 |
GetCtrlVal(pa,PA_CHANNEL, &ch); |
iRet = TMI_TimeOut(TMI_DeviceId, 1); |
iRet = TMI_Refresh(TMI_DeviceId); |
iRet = TMI_MoniDataQ(TMI_DeviceId, ch+1, &Voltage, &Current, &cv_cc); |
SetCtrlVal(panel, PA_VMON, Voltage); |
97,10 → 95,9 |
GetCtrlVal(pa,PA_CHANNEL, &ch); |
GetCtrlVal(pa,PA_PRESET, &preset); |
TMI_VoltageQ(TMI_DeviceId, ch+1, preset, &Voltage); |
TMI_CurrentQ(TMI_DeviceId, ch+1, preset, &Current); |
SetCtrlVal(pa, PA_VSET, Voltage); |
SetCtrlVal(pa, PA_ISET, Current); |
109,6 → 106,11 |
return 0; |
} |
int SetCooling(char onoff){ |
int nb=0; |
nb = ComWrt (COM_PORT, &onoff, 1); |
return nb; |
} |
#define tcpChk(f) if ((g_TCPError=(f)) < 0) {ReportTCPError(); return -1; } |
174,10 → 176,10 |
printf("Received %s\n", receiveBuf); |
int cmd=0; |
float arg; |
sscanf("%d%f",&cmd,&arg); |
sscanf(receiveBuf,"%d%f",&cmd,&arg); |
switch (cmd){ |
case 1: |
SetCtrlVal(ps.PA_TSET,arg); |
SetCtrlVal(pa,PA_TSET,arg); |
break; |
default: |
break; |
285,7 → 287,19 |
return 0; |
} |
int CVICALLBACK SwitchCoolingOnOffCB (int panel, int control, int event, |
void *callbackData, int eventData1, int eventData2) { |
int onoff=0; |
switch (event) { |
case EVENT_COMMIT: |
GetCtrlVal(pa,control,&onoff); |
SetCooling(onoff); |
break; |
} |
return 0; |
} |
int CVICALLBACK SwitchOnOffCB (int panel, int control, int event, |
void *callbackData, int eventData1, int eventData2) { |
313,8 → 327,13 |
int debug1; |
GetCtrlVal(pa,PA_DEBUG_1, &debug1); |
//printf("%f#%s#", temp, read_data); |
// temp1 , temp2 , temp3 , temp4 , temp humidity sens, rel.humidity |
if (bytes_read >0) { |
SetCtrlVal(pa,PA_ARDUINO, read_data); |
} |
sscanf(read_data,"%lf %lf %lf %lf %lf %lf",&f[0],&f[1],&f[2],&f[3],&f[4],&f[5]); |
double humidity = f[5]; |
double htemp = f[4]; |
// printf("%lf %lf %lf %lf %lf %lf",f[0],f[1],f[2],f[3],f[4],f[5]); |
int RS232Error = ReturnRS232Err (); |
if (ReturnRS232Err ()) { |
338,7 → 357,7 |
double tdiff = temp - tset; |
double retpid = UpdatePID(&pid, tdiff, temp); |
const double troom = 20; |
const double troom = htemp; |
double Pheat= 0.2 * (temp - troom); |
double Ptec = retpid - Pheat*2; |
vset = (polar*Ptec>0) ? sqrt(fabs(Ptec)) : 0; |
362,7 → 381,7 |
PlotStripChart (pa, PA_GRAPH_VMON, pgraph, 3, 0, 0, VAL_DOUBLE); |
PlotStripChart (pa, PA_GRAPH_3, &humidity, 1, 0, 0, VAL_DOUBLE); |
SetCtrlVal(pa,PA_TMON,temp); |
SetCtrlVal(pa,PA_HTMON,htemp); |
SetCtrlVal(pa,PA_HUMIDITY,humidity); |
char transmitBuf[512]= {0}; |
/cvi/apps/TempCtrl/TempCtrl.h |
---|
19,24 → 19,27 |
#define PA_START 4 /* control type: command, callback function: StartCB */ |
#define PA_TSET 5 /* control type: numeric, callback function: (none) */ |
#define PA_HUMIDITY 6 /* control type: numeric, callback function: (none) */ |
#define PA_TMON 7 /* control type: numeric, callback function: (none) */ |
#define PA_DEBUG_1 8 /* control type: radioButton, callback function: (none) */ |
#define PA_LOG 9 /* control type: radioButton, callback function: (none) */ |
#define PA_GRAPH_VMON 10 /* control type: strip, callback function: (none) */ |
#define PA_GRAPH_3 11 /* control type: strip, callback function: (none) */ |
#define PA_GRAPH 12 /* control type: strip, callback function: (none) */ |
#define PA_FNAME 13 /* control type: string, callback function: (none) */ |
#define PA_ONOFF 14 /* control type: binary, callback function: SwitchOnOffCB */ |
#define PA_CHANNEL 15 /* control type: numeric, callback function: SelectChannelCB */ |
#define PA_IMAX 16 /* control type: numeric, callback function: (none) */ |
#define PA_VMAX 17 /* control type: numeric, callback function: (none) */ |
#define PA_VSET 18 /* control type: numeric, callback function: (none) */ |
#define PA_VMON 19 /* control type: numeric, callback function: (none) */ |
#define PA_ISET 20 /* control type: numeric, callback function: (none) */ |
#define PA_POLAR 21 /* control type: ring, callback function: (none) */ |
#define PA_IMON 22 /* control type: numeric, callback function: (none) */ |
#define PA_CVCC 23 /* control type: LED, callback function: (none) */ |
#define PA_PRESET 24 /* control type: numeric, callback function: SetPresetCB */ |
#define PA_HTMON 7 /* control type: numeric, callback function: (none) */ |
#define PA_TMON 8 /* control type: numeric, callback function: (none) */ |
#define PA_DEBUG_1 9 /* control type: radioButton, callback function: (none) */ |
#define PA_LOG 10 /* control type: radioButton, callback function: (none) */ |
#define PA_GRAPH_VMON 11 /* control type: strip, callback function: (none) */ |
#define PA_GRAPH_3 12 /* control type: strip, callback function: (none) */ |
#define PA_GRAPH 13 /* control type: strip, callback function: (none) */ |
#define PA_FNAME 14 /* control type: string, callback function: (none) */ |
#define PA_ONOFF 15 /* control type: binary, callback function: SwitchOnOffCB */ |
#define PA_CHANNEL 16 /* control type: numeric, callback function: SelectChannelCB */ |
#define PA_IMAX 17 /* control type: numeric, callback function: (none) */ |
#define PA_VMAX 18 /* control type: numeric, callback function: (none) */ |
#define PA_VSET 19 /* control type: numeric, callback function: (none) */ |
#define PA_VMON 20 /* control type: numeric, callback function: (none) */ |
#define PA_ISET 21 /* control type: numeric, callback function: (none) */ |
#define PA_POLAR 22 /* control type: ring, callback function: (none) */ |
#define PA_IMON 23 /* control type: numeric, callback function: (none) */ |
#define PA_CVCC 24 /* control type: LED, callback function: (none) */ |
#define PA_PRESET 25 /* control type: numeric, callback function: SetPresetCB */ |
#define PA_FAN 26 /* control type: binary, callback function: SwitchCoolingOnOffCB */ |
#define PA_ARDUINO 27 /* control type: string, callback function: (none) */ |
/* Control Arrays: */ |
56,6 → 59,7 |
int CVICALLBACK SetPresetCB(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); |
int CVICALLBACK StartCB(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); |
int CVICALLBACK StopCB(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); |
int CVICALLBACK SwitchCoolingOnOffCB(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); |
int CVICALLBACK SwitchOnOffCB(int panel, int control, int event, void *callbackData, int eventData1, int eventData2); |
/cvi/apps/TempCtrl/TempCtrl.uir |
---|
Cannot display: file marked as a binary type. |
svn:mime-type = application/octet-stream |
/cvi/apps/TempCtrl/TempCtrl_K2231A.c |
---|
0,0 → 1,484 |
#include "K6517-ctrl.h" |
#include <tcpsupp.h> |
#include <rs232.h> |
#include <utility.h> |
#include <userint.h> |
#include <ansi_c.h> |
#include "K2231A.h" |
#include "TempCtrl.h" |
FILE *gFp; |
#define RSTREG(a,x) (a&=(~(x))) |
#define SETREG(a,x) (a|=x) |
int gMask=0xF; |
static int pa; |
#define TEXT_LENGTH 2000 |
char read_data[TEXT_LENGTH]; |
int read_term_index; |
int read_term; |
int read_cnt; |
int bytes_read; |
#define COM_PORT 11 |
typedef struct { |
double dState; // Last temperature input |
double iState; // Integrator state |
double iMax, iMin; // Maximum and minimum allowable integrator state |
double iGain, // integral gain |
pGain, // proportional gain |
dGain; // derivative gain |
} SPid; |
SPid pid; |
double UpdatePID(SPid *pid, double error, double temperature) { |
double pTerm, dTerm, iTerm; |
pTerm = pid->pGain * error; |
// calculate the proportional term |
// calculate the integral state with appropriate limiting |
pid->iState += error; |
if (pid->iState > pid->iMax) pid->iState = pid->iMax; |
else if (pid->iState < pid->iMin) pid->iState = pid->iMin; |
//if (debug ) |
iTerm = pid->iGain * pid->iState; // calculate the integral term |
dTerm = pid->dGain * (temperature - pid->dState); |
pid->dState = temperature; |
return pTerm + iTerm - dTerm; |
} |
void SetDimming(int state) { |
SetCtrlAttribute (pa, PA_START, ATTR_DIMMED, state); |
SetCtrlAttribute (pa, PA_EXIT, ATTR_DIMMED, state); |
SetCtrlAttribute (pa, PA_STOP, ATTR_DIMMED, !state); |
} |
int CVICALLBACK ReadVoltageCurrentCB (int panel, int control, int event, |
void *callbackData, int eventData1, int eventData2) { |
int iRet; |
char ch=0; |
double Voltage; |
double Current; |
char cv_cc; |
switch (event) { |
case EVENT_COMMIT: |
GetCtrlVal(pa,PA_CHANNEL, &ch); |
char cmd[0xFF]; |
K2231A_SelectChannel(ch+1); |
cv_cc = K2231A_GetOperationMode(); |
Voltage =K2231A_GetVoltageMonitor(); |
Current =K2231A_GetCurrentMonitor(); |
SetCtrlVal(panel, PA_VMON, Voltage); |
SetCtrlVal(panel, PA_IMON, Current); |
SetCtrlVal(panel, PA_CVCC, cv_cc); |
break; |
} |
return 0; |
} |
int CVICALLBACK SelectChannelCB (int panel, int control, int event, |
void *callbackData, int eventData1, int eventData2) { |
unsigned char state, preset; |
double Voltage, Current; |
unsigned char ch; |
switch (event) { |
case EVENT_COMMIT: |
GetCtrlVal(pa,PA_CHANNEL, &ch); |
K2231A_SelectChannel(ch+1); |
Voltage =K2231A_GetSetVoltage(); |
Current =K2231A_GetSetCurrent(); |
SetCtrlVal(pa, PA_VSET, Voltage); |
SetCtrlVal(pa, PA_ISET, Current); |
break; |
} |
return 0; |
} |
int SetCooling(char onoff){ |
int nb=0; |
nb = ComWrt (COM_PORT, &onoff, 1); |
return nb; |
} |
#define tcpChk(f) if ((g_TCPError=(f)) < 0) {ReportTCPError(); return -1; } |
/*---------------------------------------------------------------------------*/ |
/* Module-globals */ |
/*---------------------------------------------------------------------------*/ |
static unsigned int g_hconversation; |
static int g_TCPError = 0; |
/*---------------------------------------------------------------------------*/ |
/* Internal function prototypes */ |
/*---------------------------------------------------------------------------*/ |
/*---------------------------------------------------------------------------*/ |
/* Report TCP Errors if any */ |
/*---------------------------------------------------------------------------*/ |
static void ReportTCPError (void) { |
if (g_TCPError < 0) { |
char messageBuffer[1024]; |
sprintf(messageBuffer, |
"TCP library error message: %s\nSystem error message: %s", |
GetTCPErrorString (g_TCPError), GetTCPSystemErrorString()); |
MessagePopup ("Error", messageBuffer); |
} |
} |
int CVICALLBACK ServerTCPCB (unsigned handle, int event, int error, |
void *callbackData) { |
char receiveBuf[256] = {0}; |
ssize_t dataSize = sizeof (receiveBuf) - 1; |
char addrBuf[31]; |
switch (event) { |
case TCP_CONNECT: |
if (g_hconversation) { |
/* We already have one client, don't accept another... */ |
tcpChk (GetTCPPeerAddr (handle, addrBuf, 31)); |
sprintf (receiveBuf, "-- Refusing conection request from " |
"%s --\n", addrBuf); |
printf("%s\n", receiveBuf); |
tcpChk (DisconnectTCPClient (handle)); |
} else { |
/* Handle this new client connection */ |
g_hconversation = handle; |
tcpChk (GetTCPPeerAddr (g_hconversation, addrBuf, 31)); |
printf("%s\n", addrBuf); |
tcpChk (GetTCPPeerName (g_hconversation, receiveBuf, 256)); |
printf("%s\n", receiveBuf); |
sprintf (receiveBuf, "-- New connection from %s --\n", |
addrBuf); |
printf("%s\n", receiveBuf); |
/* Set the disconect mode so we do not need to terminate */ |
/* connections ourselves. */ |
tcpChk (SetTCPDisconnectMode (g_hconversation, TCP_DISCONNECT_AUTO)); |
} |
break; |
case TCP_DATAREADY: |
if ((dataSize = ServerTCPRead (g_hconversation, receiveBuf, dataSize, 1000)) < 0) { |
printf("Receive Error\n"); |
} else { |
receiveBuf[dataSize] = '\0'; |
printf("Received %s\n", receiveBuf); |
int cmd=0; |
float arg; |
sscanf(receiveBuf,"%d%f",&cmd,&arg); |
switch (cmd){ |
case 1: |
SetCtrlVal(pa,PA_TSET,arg); |
break; |
default: |
break; |
} |
} |
break; |
case TCP_DISCONNECT: |
if (handle == g_hconversation) { |
/* The client we were talking to has disconnected... */ |
g_hconversation = 0; |
printf("-- Client disconnected --\n"); |
/* Note that we do not need to do any more because we set the*/ |
/* disconnect mode to AUTO. */ |
} |
break; |
} |
return 0; |
} |
int main (int argc, char *argv[]) { |
int DeviceId=0; |
unsigned char ch; |
unsigned char MainOutput, preset=1; |
double Voltage, Current, tinterval; |
char str[0xFF]; |
if (InitCVIRTE (0, argv, 0) == 0) |
return -1; /* out of memory */ |
SetStdioPort (CVI_STDIO_WINDOW); |
pid.iGain= 0.1; |
pid.dGain= 2; |
pid.pGain = 5; |
pid.iMax =100; |
pid.iMin =-100 ; |
pid.iState=0; |
pid.dState=0; |
if ((pa = LoadPanel (0, "TempCtrl.uir", PA)) < 0) |
return -1; |
DisableBreakOnLibraryErrors(); |
K2231A_SetPort(6); |
K2231A_SetDebug(1); |
if (K2231A_Open()== 0) MessagePopup("Error","Cannot open USB device"); |
K2231A_Test(); |
MainOutput = K2231A_GetSwitch(); |
SetCtrlVal(pa, PA_ONOFF, MainOutput); |
SetCtrlVal(pa, PA_PRESET, preset); |
int debug1; |
GetCtrlVal(pa,PA_DEBUG_1, &debug1); |
K2231A_SetDebug(1); |
SetCtrlVal(pa,PA_CHANNEL, 0); |
/* |
GetCtrlVal(pa, P1_TINTERVAL, &tinterval); |
SetCtrlAttribute (pa, P1_TIMER, ATTR_INTERVAL, tinterval); |
*/ |
SetWaitCursor (1); |
int portNum = 10000; |
int registered = 0; |
char tempBuf[256] = {0}; |
if (RegisterTCPServer (portNum, ServerTCPCB, 0) < 0) |
MessagePopup("TCP Server", "Server registration failed!"); |
else { |
SetWaitCursor (0); |
registered = 1; |
/* We are successfully connected -- gather info */ |
if (GetTCPHostAddr (tempBuf, 256) >= 0) printf("%s\n" ,tempBuf); |
if (GetTCPHostName (tempBuf, 256) >= 0) printf("%s\n" ,tempBuf); |
} |
SelectChannelCB (pa, PA_CHANNEL, EVENT_COMMIT, NULL, 0,0); |
ReadVoltageCurrentCB (pa, PA_CHANNEL, EVENT_COMMIT, NULL, 0,0); |
DisplayPanel (pa); |
SetDimming(0); |
RunUserInterface (); |
CloseCom(COM_PORT); |
if (registered) |
UnregisterTCPServer (portNum); |
DiscardPanel (pa); |
K2231A_Close(); |
if (gFp) fclose(gFp); |
return 0; |
} |
int CVICALLBACK ExitCB (int panel, int control, int event, |
void *callbackData, int eventData1, int eventData2) { |
switch (event) { |
case EVENT_COMMIT: |
QuitUserInterface (0); |
break; |
} |
return 0; |
} |
int CVICALLBACK SwitchCoolingOnOffCB (int panel, int control, int event, |
void *callbackData, int eventData1, int eventData2) { |
int onoff=0; |
switch (event) { |
case EVENT_COMMIT: |
GetCtrlVal(pa,control,&onoff); |
SetCooling(onoff); |
break; |
} |
return 0; |
} |
int CVICALLBACK SwitchOnOffCB (int panel, int control, int event, |
void *callbackData, int eventData1, int eventData2) { |
unsigned char state; |
switch (event) { |
case EVENT_COMMIT: |
GetCtrlVal(panel, control, &state); |
K2231A_SetSwitch(state); |
break; |
} |
return 0; |
} |
/* Callback Function */ |
void ComCallback(int portNumber, int eventMask, void *callbackdata) { |
static double told=0; |
if (eventMask & LWRS_RXFLAG) { |
//printf("Received specified character\n"); |
int strLen = GetInQLen (COM_PORT); |
bytes_read = ComRd (COM_PORT, read_data, strLen); |
double temp= atof(read_data); |
double f[10]; |
int debug1; |
GetCtrlVal(pa,PA_DEBUG_1, &debug1); |
K2231A_SetDebug(debug1); |
//printf("%f#%s#", temp, read_data); |
// temp1 , temp2 , temp3 , temp4 , temp humidity sens, rel.humidity |
if (bytes_read >0) { |
SetCtrlVal(pa,PA_ARDUINO, read_data); |
} |
sscanf(read_data,"%lf %lf %lf %lf %lf %lf",&f[0],&f[1],&f[2],&f[3],&f[4],&f[5]); |
double humidity = f[5]; |
double htemp = f[4]; |
// printf("%lf %lf %lf %lf %lf %lf",f[0],f[1],f[2],f[3],f[4],f[5]); |
int RS232Error = ReturnRS232Err (); |
if (ReturnRS232Err ()) { |
sprintf(read_data,"#%s\n", GetRS232ErrorString(RS232Error)); |
MessagePopup("RS232Err",read_data); |
} else { |
int polar; |
ProcessSystemEvents (); |
SelectChannelCB (pa, PA_CHANNEL, EVENT_COMMIT, NULL, 0,0); |
ProcessSystemEvents (); |
ReadVoltageCurrentCB (pa, PA_CHANNEL, EVENT_COMMIT, NULL, 0,0); |
ProcessSystemEvents (); |
double tset,vmon,imon,vset,iset,vmax; |
unsigned char ch, preset; |
GetCtrlVal(pa,PA_TSET,&tset); |
GetCtrlVal(pa,PA_VMON,&vmon); |
GetCtrlVal(pa,PA_IMON,&imon); |
GetCtrlVal(pa,PA_CHANNEL, &ch); |
//GetCtrlVal(pa,PA_PRESET,&preset); |
//TMI_Preset(TMI_DeviceId,preset); |
GetCtrlVal(pa,PA_POLAR,&polar); |
double tdiff = temp - tset; |
double retpid = UpdatePID(&pid, tdiff, temp); |
const double troom = htemp; |
double Pheat= 0.2 * (temp - troom); |
double Ptec = retpid - Pheat*2; |
vset = (polar*Ptec>0) ? sqrt(fabs(Ptec)) : 0; |
if (debug1) printf("%d PID tmon=%f tset=%f tdiff=%f vmon=%f imom=%f pid=%f Pheat=%f =>vset %f", ch, temp, tset, tdiff, vmon, imon,retpid ,Pheat, vset); |
GetCtrlVal(pa,PA_VMAX,&vmax); |
if (vset >vmax) vset=vmax; |
if (vset <0) vset =0; |
if (debug1) printf("vset --->%f \n",vset); |
K2231A_SelectChannel(ch+1); |
K2231A_SetVoltage(vset); |
GetCtrlVal(pa,PA_IMAX,&iset); |
K2231A_SetCurrent(iset); |
ReadVoltageCurrentCB (pa, PA_CHANNEL, EVENT_COMMIT, NULL, 0,0); |
PlotStripChart (pa, PA_GRAPH, &temp, 1, 0, 0, VAL_DOUBLE); |
double pgraph[3]= {vmon,imon, 100*(temp-told)}; |
PlotStripChart (pa, PA_GRAPH_VMON, pgraph, 3, 0, 0, VAL_DOUBLE); |
PlotStripChart (pa, PA_GRAPH_3, &humidity, 1, 0, 0, VAL_DOUBLE); |
SetCtrlVal(pa,PA_TMON,temp); |
SetCtrlVal(pa,PA_HTMON,htemp); |
SetCtrlVal(pa,PA_HUMIDITY,humidity); |
char transmitBuf[512]= {0}; |
sprintf(transmitBuf, "%u %f %f %f %f\n", time(NULL), humidity, temp, tdiff, temp-told); |
if (g_hconversation) |
if ( ServerTCPWrite (g_hconversation, transmitBuf, strlen (transmitBuf), 1000) < 0) printf("Transmit Error\n"); |
int log=0; |
GetCtrlVal(pa,PA_LOG, &log); |
if (log) { |
char fname[0xFF]; |
GetCtrlVal(pa,PA_FNAME, fname); |
FILE *fp = fopen (fname,"a"); |
fprintf(fp,transmitBuf); |
fclose(fp); |
} |
told= temp; |
} |
} |
if (eventMask & LWRS_TXEMPTY) |
printf("Transmit queue now empty\n"); |
if (eventMask & LWRS_RECEIVE) { |
printf("50 or more bytes in input queue\n"); |
} |
} |
int CVICALLBACK StartCB (int panel, int control, int event, |
void *callbackData, int eventData1, int eventData2) { |
switch (event) { |
case EVENT_COMMIT: |
OpenComConfig (COM_PORT, "", 115200, 0, 8, 1, 512, 512); |
/* Turn off Hardware handshaking (loopback test will not function with it on) */ |
SetCTSMode (COM_PORT, LWRS_HWHANDSHAKE_OFF); |
/* Make sure Serial buffers are empty */ |
FlushInQ (COM_PORT); |
FlushOutQ (COM_PORT); |
int notifyCount = 50; /* Wait for at least 50 bytes in queue. */ |
int eventChar = 10; /* Wait for LF. */ |
int eventMask = LWRS_RXFLAG | LWRS_TXEMPTY | LWRS_RECEIVE; |
InstallComCallback (COM_PORT, eventMask, notifyCount, eventChar, ComCallback, NULL); |
SetDimming(1); |
break; |
} |
return 0; |
} |
int CVICALLBACK StopCB (int panel, int control, int event, |
void *callbackData, int eventData1, int eventData2) { |
switch (event) { |
case EVENT_COMMIT: |
CloseCom(COM_PORT); |
SetDimming(0); |
break; |
} |
return 0; |
} |
int CVICALLBACK SetPresetCB (int panel, int control, int event, |
void *callbackData, int eventData1, int eventData2) { |
switch (event) { |
case EVENT_COMMIT: { |
unsigned char preset; |
double Voltage, Current; |
GetCtrlVal(panel, control, &preset); |
K2231A_RecallFromMemory(preset); |
break; |
} |
} |
return 0; |
} |
/cvi/apps/TempCtrl/TempCtrl_K2231A.prj |
---|
0,0 → 1,432 |
[Project Header] |
Version = 1302 |
Pathname = "/c/home/CVI/apps/TempCtrl/TempCtrl_K2231A.prj" |
CVI Dir = "/c/program files/national instruments/cvi2013" |
CVI Shared Dir = "/C/Program Files/National Instruments/Shared/CVI" |
CVI Pub Local Dir = "/C/ProgramData/National Instruments/CVI2013" |
CVI Pub Global Dir = "/C/ProgramData/National Instruments/CVI" |
IVI Standard Root Dir = "/C/Program Files/IVI Foundation/IVI" |
VXIplug&play Framework Dir = "/C/Program Files/IVI Foundation/VISA/winnt" |
IVI Standard Root 64-bit Dir = "/C/Program Files/IVI Foundation/IVI" |
VXIplug&play Framework 64-bit Dir = "/C/Program Files/IVI Foundation/VISA/win64" |
Number of Files = 3 |
Target Type = "Executable" |
Flags = 2064 |
Copied From Locked InstrDrv Directory = False |
Copied from VXIPNP Directory = False |
Locked InstrDrv Name = "" |
Don't Display Deploy InstrDrv Dialog = False |
[Folders] |
Include Files Folder Not Added Yet = True |
Library Files Folder Not Added Yet = True |
Folder 0 = "Source Files" |
FolderEx 0 = "Source Files" |
Folder 1 = "Instrument Files" |
FolderEx 1 = "Instrument Files" |
Folder 2 = "User Interface Files" |
FolderEx 2 = "User Interface Files" |
[File 0001] |
File Type = "CSource" |
Res Id = 1 |
Path Is Rel = True |
Path Rel To = "Project" |
Path Rel Path = "TempCtrl_K2231A.c" |
Path = "/c/home/CVI/apps/TempCtrl/TempCtrl_K2231A.c" |
Exclude = False |
Compile Into Object File = False |
Project Flags = 0 |
Folder = "Source Files" |
Folder Id = 0 |
[File 0002] |
File Type = "Function Panel" |
Res Id = 2 |
Path Is Rel = True |
Path Rel To = "Project" |
Path Rel Path = "../../instr/K2231A/K2231A.fp" |
Path = "/c/home/CVI/instr/K2231A/K2231A.fp" |
Exclude = False |
Project Flags = 0 |
Folder = "Instrument Files" |
Folder Id = 1 |
[File 0003] |
File Type = "User Interface Resource" |
Res Id = 3 |
Path Is Rel = True |
Path Rel To = "Project" |
Path Rel Path = "TempCtrl.uir" |
Path = "/c/home/CVI/apps/TempCtrl/TempCtrl.uir" |
Exclude = False |
Project Flags = 0 |
Folder = "User Interface Files" |
Folder Id = 2 |
[Custom Build Configs] |
Num Custom Build Configs = 0 |
[Default Build Config Debug] |
Config Name = "Debug" |
Is 64-Bit = False |
Is Release = False |
Default Calling Convention = "cdecl" |
Optimization Level = "Optimize for speed (level 2)" |
Require Prototypes = True |
Show Warning IDs in Build Output = False |
Selected Warning Level = "None" |
Warning List None = "4,9,84,105,106,107,108,109,110,111" |
Warning List Common = "" |
Warning List Extended = "" |
Warning List All = "" |
Warning Mode = 0 |
Enable Unreferenced Identifiers Warning = False |
Enable Pointer Mismatch Warning = False |
Enable Unreachable Code Warning = False |
Enable Assignment In Conditional Warning = False |
Uninitialized Locals Compile Warning = "Aggressive" |
Require Return Values = True |
Enable C99 Extensions = False |
Enable OpenMP Extensions = False |
Stack Size = 500000 |
Stack Reserve = 1048576 |
Stack Commit = 4096 |
Image Base Address = 4194304 |
Image Base Address x64 = 4194304 |
Compiler Defines = "/DWIN32_LEAN_AND_MEAN" |
Sign = False |
Sign Store = "" |
Sign Certificate = "" |
Sign Timestamp URL = "" |
Sign URL = "" |
Manifest Embed = False |
Icon File Is Rel = False |
Icon File = "" |
Application Title = "" |
Use IVI Subdirectories for Import Libraries = False |
Use VXIPNP Subdirectories for Import Libraries = False |
Use Dflt Import Lib Base Name = True |
Where to Copy DLL = "Do not copy" |
Custom Directory to Copy DLL Is Rel = False |
Custom Directory to Copy DLL = "" |
Generate Source Documentation = "None" |
Runtime Support = "Full Runtime Support" |
Runtime Binding = "Shared" |
Embed Project .UIRs = False |
Generate Map File = False |
Embed Timestamp = True |
Create Console Application = False |
Using LoadExternalModule = False |
DLL Exports = "Include File Symbols" |
Register ActiveX Server = False |
Numeric File Version = "1,0,0,0" |
Numeric Prod Version = "1,0,0,0" |
Comments = "" |
Comments Ex = "" |
Company Name = "" |
Company Name Ex = "%company" |
File Description = "TempCtrl_K2231A (Debug x86)" |
File Description Ex = "%application (%rel_dbg %arch)" |
File Version = "1.0" |
File Version Ex = "%f1.%f2" |
Internal Name = "TempCtrl_K2231A" |
Internal Name Ex = "%basename" |
Legal Copyright = "Copyright © 2018" |
Legal Copyright Ex = "Copyright © %company %Y" |
Legal Trademarks = "" |
Legal Trademarks Ex = "" |
Original Filename = "TempCtrl_K2231A.exe" |
Original Filename Ex = "%filename" |
Private Build = "" |
Private Build Ex = "" |
Product Name = " TempCtrl_K2231A" |
Product Name Ex = "%company %application" |
Product Version = "1.0" |
Product Version Ex = "%p1.%p2" |
Special Build = "" |
Special Build Ex = "" |
Add Type Lib To DLL = False |
Include Type Lib Help Links = False |
TLB Help Style = "HLP" |
Type Lib FP File Is Rel = False |
Type Lib FP File = "" |
[Default Build Config Release] |
Config Name = "Release" |
Is 64-Bit = False |
Is Release = True |
Default Calling Convention = "cdecl" |
Optimization Level = "Optimize for speed (level 2)" |
Require Prototypes = True |
Show Warning IDs in Build Output = False |
Selected Warning Level = "None" |
Warning List None = "4,9,84,105,106,107,108,109,110,111" |
Warning List Common = "" |
Warning List Extended = "" |
Warning List All = "" |
Warning Mode = 0 |
Enable Unreferenced Identifiers Warning = False |
Enable Pointer Mismatch Warning = False |
Enable Unreachable Code Warning = False |
Enable Assignment In Conditional Warning = False |
Uninitialized Locals Compile Warning = "Aggressive" |
Require Return Values = True |
Enable C99 Extensions = False |
Enable OpenMP Extensions = False |
Stack Size = 500000 |
Stack Reserve = 1048576 |
Stack Commit = 4096 |
Image Base Address = 4194304 |
Image Base Address x64 = 4194304 |
Compiler Defines = "/DWIN32_LEAN_AND_MEAN /DCAEN_V1718 /DBELLEPTS" |
Sign = False |
Sign Store = "" |
Sign Certificate = "" |
Sign Timestamp URL = "" |
Sign URL = "" |
Manifest Embed = False |
Icon File Is Rel = False |
Icon File = "" |
Application Title = "" |
Use IVI Subdirectories for Import Libraries = False |
Use VXIPNP Subdirectories for Import Libraries = False |
Use Dflt Import Lib Base Name = True |
Where to Copy DLL = "Do not copy" |
Custom Directory to Copy DLL Is Rel = False |
Custom Directory to Copy DLL = "" |
Generate Source Documentation = "None" |
Runtime Support = "Full Runtime Support" |
Runtime Binding = "Shared" |
Embed Project .UIRs = False |
Generate Map File = False |
Embed Timestamp = True |
Create Console Application = False |
Using LoadExternalModule = False |
DLL Exports = "Include File Symbols" |
Register ActiveX Server = False |
Add Type Lib To DLL = False |
Include Type Lib Help Links = False |
TLB Help Style = "HLP" |
Type Lib FP File Is Rel = False |
Type Lib FP File = "" |
[Default Build Config Debug64] |
Config Name = "Debug64" |
Is 64-Bit = True |
Is Release = False |
Default Calling Convention = "cdecl" |
Optimization Level = "Optimize for speed (level 2)" |
Require Prototypes = True |
Show Warning IDs in Build Output = False |
Selected Warning Level = "None" |
Warning List None = "4,9,84,105,106,107,108,109,110,111" |
Warning List Common = "" |
Warning List Extended = "" |
Warning List All = "" |
Warning Mode = 0 |
Enable Unreferenced Identifiers Warning = False |
Enable Pointer Mismatch Warning = False |
Enable Unreachable Code Warning = False |
Enable Assignment In Conditional Warning = False |
Uninitialized Locals Compile Warning = "Aggressive" |
Require Return Values = True |
Enable C99 Extensions = False |
Enable OpenMP Extensions = False |
Stack Size = 500000 |
Stack Reserve = 1048576 |
Stack Commit = 4096 |
Image Base Address = 4194304 |
Image Base Address x64 = 4194304 |
Compiler Defines = "/DWIN32_LEAN_AND_MEAN /DCAEN_V1718 /DBELLEPTS" |
Sign = False |
Sign Store = "" |
Sign Certificate = "" |
Sign Timestamp URL = "" |
Sign URL = "" |
Manifest Embed = False |
Icon File Is Rel = False |
Icon File = "" |
Application Title = "" |
Use IVI Subdirectories for Import Libraries = False |
Use VXIPNP Subdirectories for Import Libraries = False |
Use Dflt Import Lib Base Name = True |
Where to Copy DLL = "Do not copy" |
Custom Directory to Copy DLL Is Rel = False |
Custom Directory to Copy DLL = "" |
Generate Source Documentation = "None" |
Runtime Support = "Full Runtime Support" |
Runtime Binding = "Shared" |
Embed Project .UIRs = False |
Generate Map File = False |
Embed Timestamp = True |
Create Console Application = False |
Using LoadExternalModule = False |
DLL Exports = "Include File Symbols" |
Register ActiveX Server = False |
Add Type Lib To DLL = False |
Include Type Lib Help Links = False |
TLB Help Style = "HLP" |
Type Lib FP File Is Rel = False |
Type Lib FP File = "" |
[Default Build Config Release64] |
Config Name = "Release64" |
Is 64-Bit = True |
Is Release = True |
Default Calling Convention = "cdecl" |
Optimization Level = "Optimize for speed (level 2)" |
Require Prototypes = True |
Show Warning IDs in Build Output = False |
Selected Warning Level = "None" |
Warning List None = "4,9,84,105,106,107,108,109,110,111" |
Warning List Common = "" |
Warning List Extended = "" |
Warning List All = "" |
Warning Mode = 0 |
Enable Unreferenced Identifiers Warning = False |
Enable Pointer Mismatch Warning = False |
Enable Unreachable Code Warning = False |
Enable Assignment In Conditional Warning = False |
Uninitialized Locals Compile Warning = "Aggressive" |
Require Return Values = True |
Enable C99 Extensions = False |
Enable OpenMP Extensions = False |
Stack Size = 500000 |
Stack Reserve = 1048576 |
Stack Commit = 4096 |
Image Base Address = 4194304 |
Image Base Address x64 = 4194304 |
Compiler Defines = "/DWIN32_LEAN_AND_MEAN /DCAEN_V1718 /DBELLEPTS" |
Sign = False |
Sign Store = "" |
Sign Certificate = "" |
Sign Timestamp URL = "" |
Sign URL = "" |
Manifest Embed = False |
Icon File Is Rel = False |
Icon File = "" |
Application Title = "" |
Use IVI Subdirectories for Import Libraries = False |
Use VXIPNP Subdirectories for Import Libraries = False |
Use Dflt Import Lib Base Name = True |
Where to Copy DLL = "Do not copy" |
Custom Directory to Copy DLL Is Rel = False |
Custom Directory to Copy DLL = "" |
Generate Source Documentation = "None" |
Runtime Support = "Full Runtime Support" |
Runtime Binding = "Shared" |
Embed Project .UIRs = False |
Generate Map File = False |
Embed Timestamp = True |
Create Console Application = False |
Using LoadExternalModule = False |
DLL Exports = "Include File Symbols" |
Register ActiveX Server = False |
Add Type Lib To DLL = False |
Include Type Lib Help Links = False |
TLB Help Style = "HLP" |
Type Lib FP File Is Rel = False |
Type Lib FP File = "" |
[Compiler Options] |
Default Calling Convention = "cdecl" |
Require Prototypes = True |
Require Return Values = True |
Enable Pointer Mismatch Warning = False |
Enable Unreachable Code Warning = False |
Enable Unreferenced Identifiers Warning = False |
Enable Assignment In Conditional Warning = False |
O Option Compatible With 5.0 = False |
Enable C99 Extensions = False |
Uninitialized Locals Compile Warning = "Aggressive" |
Precompile Prefix Header = False |
Prefix Header File = "" |
[Run Options] |
Stack Size = 500000 |
Stack Commit = 4096 |
Image Base Address = 4194304 |
Image Base Address x64 = 4194304 |
[Compiler Defines] |
Compiler Defines = "/DWIN32_LEAN_AND_MEAN /DCAEN_V1718 /DBELLEPTS" |
[Create Executable] |
Executable File_Debug Is Rel = True |
Executable File_Debug Rel To = "Project" |
Executable File_Debug Rel Path = "TempCtrl_K2231A.exe" |
Executable File_Debug = "/c/home/CVI/apps/TempCtrl/TempCtrl_K2231A.exe" |
Executable File_Release Is Rel = True |
Executable File_Release Rel To = "Project" |
Executable File_Release Rel Path = "TempCtrl_K2231A.exe" |
Executable File_Release = "/c/home/CVI/apps/TempCtrl/TempCtrl_K2231A.exe" |
Executable File_Debug64 Is Rel = True |
Executable File_Debug64 Rel To = "Project" |
Executable File_Debug64 Rel Path = "TempCtrl_K2231A.exe" |
Executable File_Debug64 = "/c/home/CVI/apps/TempCtrl/TempCtrl_K2231A.exe" |
Executable File_Release64 Is Rel = True |
Executable File_Release64 Rel To = "Project" |
Executable File_Release64 Rel Path = "TempCtrl_K2231A.exe" |
Executable File_Release64 = "/c/home/CVI/apps/TempCtrl/TempCtrl_K2231A.exe" |
Icon File Is Rel = False |
Icon File = "" |
Application Title = "" |
DLL Exports = "Include File Symbols" |
Use IVI Subdirectories for Import Libraries = False |
Use VXIPNP Subdirectories for Import Libraries = False |
Use Dflt Import Lib Base Name = True |
Where to Copy DLL = "Do not copy" |
Custom Directory to Copy DLL Is Rel = False |
Custom Directory to Copy DLL = "" |
Generate Source Documentation = "None" |
Add Type Lib To DLL = False |
Include Type Lib Help Links = False |
TLB Help Style = "HLP" |
Type Lib FP File Is Rel = False |
Type Lib FP File = "" |
Type Lib Guid = "" |
Runtime Support = "Full Runtime Support" |
Instrument Driver Support Only = False |
Embed Project .UIRs = False |
Generate Map File = False |
[External Compiler Support] |
UIR Callbacks File Option = 0 |
Using LoadExternalModule = False |
Create Project Symbols File = True |
UIR Callbacks Obj File Is Rel = False |
UIR Callbacks Obj File = "" |
Project Symbols H File Is Rel = False |
Project Symbols H File = "" |
Project Symbols Obj File Is Rel = False |
Project Symbols Obj File = "" |
[ActiveX Server Options] |
Specification File Is Rel = False |
Specification File = "" |
Source File Is Rel = False |
Source File = "" |
Include File Is Rel = False |
Include File = "" |
IDL File Is Rel = False |
IDL File = "" |
Register ActiveX Server = False |
[Signing Info] |
Sign = False |
Sign Debug Build = False |
Store = "" |
Certificate = "" |
Timestamp URL = "" |
URL = "" |
[Manifest Info] |
Embed = False |
[tpcSection] |
tpcEnabled = 0 |
tpcOverrideEnvironment = 0 |
tpcEnabled x64 = 0 |
tpcOverrideEnvironment x64 = 0 |