06-21-2007 05:46 AM
06-25-2007 05:31 AM
06-28-2007 12:13 AM
06-28-2007 02:43 AM
07-02-2007 02:42 AM
07-08-2008 05:06 AM
07-08-2008 09:05 AM
Hello Malte
I eventually found the following code in CVI worked.
#include <ansi_c.h>
#include <rs232.h>
#include <utility.h>
#include <formatio.h>
#include "RS232-GPIB.h"
#define COM_PORT 4
#define COM_PORT_TEXT "COM4"
static int panelHandle;
int ComError,BytesWritten;
int BytesRead;
char databuf[120];
char Status[100]; /*GPIB Status*/
char GPIBerr[100]; /*GPIB Error number*/
char SPerr[100]; /*Serial Port Error number*/
char count[5]; /*Byte count or reads or writes*/
double temperature;
int humidity;
void CheckGPIBError (void); /**Currently UnUsed!**/
void ReadAllStatus(void);
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "RS232-GPIB.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
RunUserInterface ();
DiscardPanel (panelHandle);
return 0;
}
int CVICALLBACK INITIALIZE (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
ComError = OpenComConfig(COM_PORT,COM_PORT_TEXT,9600,0,8,1,512,512);
ReturnRS232Err();
ComError=SetCTSMode(COM_PORT,1);
ReturnRS232Err();
BytesWritten = ComWrt(COM_PORT, "onl 0\r" ,6);
Delay(1);
BytesWritten = ComWrt(COM_PORT,"onl 1\r",6);
Delay(1);
Delay(1);
FlushInQ (COM_PORT);
BytesWritten = ComWrt(COM_PORT,"onl 1\r",6);
CheckGPIBError();
SetCtrlAttribute (panelHandle, PANEL_INITIALIZE, ATTR_DIMMED, 1);
SetCtrlAttribute(panelHandle, PANEL_TIMER, ATTR_ENABLED, 1);
break;
}
return 0;
}
int CVICALLBACK TIMER (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_TIMER_TICK:
//Open Comm Port
BytesWritten = ComWrt(COM_PORT,"wrt 3\n*IDN?\r\n",13);
CheckGPIBError(); // Miss out of main program
BytesWritten = ComWrt(COM_PORT,"rd #70 3\r\n",10);
BytesRead = ComRdTerm (COM_PORT, databuf, 100, 13);
CheckGPIBError();
//Fmt(databuf,"%s<%s"," 32.5F49P0>CT: 32.53C1 rh:49%10T 24.3"); These are examples of the string that is returned from the cabinet
//Fmt(databuf,"%s<%s","-31.9F 0P0>CT:-31.93C0 0T 24.3");
Scan(databuf,"%s>%fF%i",&temperature, &humidity);
SetCtrlVal(panelHandle, PANEL_Temp, temperature);
SetCtrlVal(panelHandle, PANEL_rh, humidity);
break;
}
return 0;
}
int CVICALLBACK EXIT (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
// Close COMM PORT
SetCtrlAttribute(panelHandle, PANEL_TIMER, ATTR_ENABLED, 0);
ComError=CloseCom (COM_PORT);
ReturnRS232Err();
QuitUserInterface (0);
break;
}
return 0;
}
void CheckGPIBError (void)
{
int GPIBErrCode;
int hexStat;
int InQLen;
Delay (0.1);
FlushInQ (COM_PORT);
BytesWritten = ComWrt (COM_PORT, "stat n\r", 7);
InQLen = GetInQLen (COM_PORT);
while (InQLen < 4)
InQLen = GetInQLen (COM_PORT);
ReadAllStatus();
Scan (Status, "%s>%d", &hexStat);
Scan (GPIBerr, "%s>%d", &GPIBErrCode);
if (hexStat < 0)
{
printf("GPIB Error: GPIB error code = %d\n", GPIBErrCode);
exit (0);
}
}
void ReadAllStatus(void)
{
BytesRead = ComRdTerm (COM_PORT, Status, 10, 13);
BytesRead = ComRdTerm (COM_PORT, GPIBerr, 5, 13);
BytesRead = ComRdTerm (COM_PORT, SPerr, 5, 13);
BytesRead = ComRdTerm (COM_PORT, count, 5, 13);
}
Hope this helps
Paul
07-08-2008 09:33 AM
07-08-2008 10:20 AM