Subversion Repositories f9daq

Compare Revisions

No changes between revisions

Ignore whitespace Rev 258 → Rev 259

/cvi/instr/hm7044/example.c
0,0 → 1,117
#include <ansi_c.h>
#include <utility.h>
#include "hm7044ui.h"
#include "hm7044.h"
 
static int panelHandle;
 
int test(){
char result[MAX_CMD] ;
char cmd[MAX_CMD] ;
float data[4];
int port;
int err;
int i,ch=1;
GetCtrlVal(panelHandle,PANEL_PORT,&port);
GetCtrlVal(panelHandle,PANEL_CMD ,cmd);
err=HM7044_Open (port);
HM7044_SendCmd("FUSE 1,2,3,4",result);
HM7044_FuseOff( ch);
HM7044_SetVoltage(ch,1);
HM7044_Enable_Output( ch);
for (i=0;i<10;i++){
HM7044_SwitchOff(ch);
HM7044_SetCurrent(ch,i/1000.);
//HM7044_SetVoltage(ch,i/100.);
HM7044_SwitchOn(ch);
Delay(0.5);
HM7044_Read(data);
}
HM7044_Disable_Output(ch);
err= HM7044_Close() ;
printf ( "[%d] Port closed.\n" ,err) ;
return 0;
}
 
int mymain(){
 
char result[MAX_CMD] ;
char cmd[MAX_CMD] ;
float data[4];
int port;
int err;
GetCtrlVal(panelHandle,PANEL_PORT,&port);
GetCtrlVal(panelHandle,PANEL_CMD ,cmd);
err=HM7044_Open (port);
printf ( "[%d] Port %d opened \n",err,port) ;
 
HM7044_SendCmd (cmd, result );
printf ( "\nRecieved response:#%s#\n",result ) ;
SetCtrlVal(panelHandle,PANEL_READ ,result);
SetCtrlVal(panelHandle,PANEL_READ ,"\n");
err= HM7044_Close() ;
printf ( "[%d] Port closed.\n" ,err) ;
return 0;
}
 
 
 
int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
if (InitCVIRTE (hInstance, 0, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "hm7044ui.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);
SetStdioPort (CVI_STDIO_WINDOW);
RunUserInterface ();
 
DiscardPanel (panelHandle);
return 0;
}
 
int CVICALLBACK Send (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
mymain();
break;
}
return 0;
}
int CVICALLBACK TestCB (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
test();
break;
}
return 0;
}
int CVICALLBACK Exit (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
QuitUserInterface (0);
break;
}
return 0;
}
 
 
/cvi/instr/hm7044/hm7044.c
0,0 → 1,183
#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;
sprintf ( str1, "%s\r", cmd ) ;
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];
sprintf(cmd1,"%s %d",cmd,val);
return HM7044_SendCmd(cmd1,result);
}
 
static int send_float( char* cmd,float val, char* result ) {
char cmd1[MAX_CMD];
sprintf(cmd1,"%s %f",cmd,val);
return HM7044_SendCmd(cmd1,result);
}
 
int HM7044_SetVoltage(int ch, float value){
char cmd[MAX_CMD];
send_int("SEL",ch, gresult);
sprintf(cmd,"SET %4.2f V",value);
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);
sprintf(cmd,"SET %f A",value);
HM7044_SendCmd(cmd, gresult);
HM7044_SendCmd("SEL NONE", gresult);
return 0;
}
 
 
int HM7044_Read( float *data){
int nb,i;
com_send("READ");
printf ( "\n");
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;
}
 
/cvi/instr/hm7044/hm7044.fp
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/cvi/instr/hm7044/hm7044.h
0,0 → 1,13
#define MAX_CMD 1024
int HM7044_Open(int port);
int HM7044_Close(void);
int HM7044_SetVoltage(int ch, float value);
int HM7044_SetCurrent(int ch, float value);
int HM7044_Read( float *data);
int HM7044_Enable_Output(int ch);
int HM7044_Disable_Output(int ch);
int HM7044_SwitchOn(int ch);
int HM7044_SwitchOff(int ch);
int HM7044_SendCmd ( char* cmd, char* result );
int HM7044_FuseOn(int ch);
int HM7044_FuseOff(int ch);
/cvi/instr/hm7044/hm7044.prj
0,0 → 1,194
[Project Header]
Version = 551
Platform Code = 4
Pathname = "/c/MeasurementStudio/cvi/instr/hm7044/hm7044.prj"
CVI Dir = "/c/measurementstudio/cvi"
VXIplug&play Framework Dir = "/C/VXIPNP/winnt"
Number of Files = 5
Sort Type = "No Sort"
Target Type = "Executable"
Build Configuration = "Debug"
Warn User If Debugging Release = 1
Flags = 16
Drag Bar Left = 135
Window Top = 77
Window Left = 420
Window Bottom = 379
Window Right = 960
 
[File 0001]
File Type = "CSource"
Path = "/c/MeasurementStudio/cvi/instr/hm7044/hm7044.c"
Res Id = 1
Exclude = False
Disk Date = 3187853080
Project Flags = 0
Compile Into Object File = False
Object Format = "Win32-MSVC"
ForceCompile_Debug = False
ForceCompile_Release = True
Window Top = 74
Window Left = 193
Window Height = 0
Window Width = 0
Source Window State = "1,125,125,125,36,36,37,0,0,80,0,1,0,1,0,25,110,0,127,28,"
Header Dependencies = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,"
 
[File 0002]
File Type = "Function Panel"
Path = "/c/MeasurementStudio/cvi/instr/hm7044/hm7044.fp"
Res Id = 2
Exclude = False
Disk Date = 3187852036
Project Flags = 0
Window Top = 0
Window Left = 0
Window Height = 0
Window Width = 0
 
[File 0003]
File Type = "User Interface Resource"
Path = "/c/MeasurementStudio/cvi/instr/hm7044/hm7044ui.uir"
Res Id = 3
Exclude = False
Disk Date = 3187852316
Project Flags = 0
Window Top = 232
Window Left = 114
Window Height = 400
Window Width = 676
 
[File 0004]
File Type = "Include"
Path = "/c/MeasurementStudio/cvi/instr/hm7044/hm7044.h"
Res Id = 4
Exclude = False
Disk Date = 3187851746
Project Flags = 0
Window Top = 254
Window Left = 135
Window Height = 0
Window Width = 0
Source Window State = "1,8,10,8,0,-1,0,0,0,80,0,0,0,0,0,25,0,0,13,11,"
 
[File 0005]
File Type = "CSource"
Path = "/c/MeasurementStudio/cvi/instr/hm7044/example.c"
Res Id = 5
Exclude = False
Disk Date = 3189076472
Project Flags = 0
Compile Into Object File = False
Object Format = "Win32-MSVC"
ForceCompile_Debug = False
ForceCompile_Release = True
Window Top = 277
Window Left = 135
Window Height = 0
Window Width = 0
Source Window State = "1,18,18,18,3,9,3,0,0,80,0,2,0,2,0,25,8,0,17,71,"
Header Dependencies = "1,2,3,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,"
 
[SCC Options]
Use global settings = True
SCC Provider = ""
SCC Project = ""
Local Path = ""
Auxiliary Path = ""
Perform Same Action For .h File As For .uir File = "Ask"
Comment = ""
Username = ""
Use Default Comment = False
Use Default Username = False
Do Not Include PRJ File in Actions = True
Suppress CVI Error Messages = False
 
[Compiler Options]
Default Calling Convention = "cdecl"
Max Number Of Errors = 10
Require Prototypes = True
Require Return Values = True
Enable Pointer Mismatch Warning = False
Enable Unreachable Code Warning = False
Track Include File Dependencies = True
Prompt For Missing Includes = True
Stop On First Error File = False
Bring Up Err Win For Warnings = True
Show Build Dialog = False
O Option Compatible With 5.0 = False
 
[Run Options]
Stack Size = 250000
Debugging Level = "Standard"
Save Changes Before Running = "Ask"
Break On Library Errors = True
Break On First Chance Exceptions = False
Hide Windows = False
Break At First Statement = False
 
[Compiler Defines]
Compiler Defines = "/DWIN32_LEAN_AND_MEAN"
 
[Command Line Args]
Command Line Args = ""
 
[Included Headers]
Header 0022 = "/c/MeasurementStudio/cvi/instr/hm7044/hm7044.h"
Header 0001 = "/c/MeasurementStudio/cvi/include/utility.h"
Header 0002 = "/c/MeasurementStudio/cvi/include/cvidef.h"
Header 0003 = "/c/MeasurementStudio/cvi/include/cvirte.h"
Header 0004 = "/c/MeasurementStudio/cvi/include/rs232.h"
Header 0005 = "/c/MeasurementStudio/cvi/include/ansi_c.h"
Header 0006 = "/c/MeasurementStudio/cvi/include/ansi/assert.h"
Header 0007 = "/c/MeasurementStudio/cvi/include/ansi/ctype.h"
Header 0008 = "/c/MeasurementStudio/cvi/include/ansi/errno.h"
Header 0009 = "/c/MeasurementStudio/cvi/include/ansi/float.h"
Header 0010 = "/c/MeasurementStudio/cvi/include/ansi/limits.h"
Header 0011 = "/c/MeasurementStudio/cvi/include/ansi/locale.h"
Header 0012 = "/c/MeasurementStudio/cvi/include/ansi/math.h"
Header 0013 = "/c/MeasurementStudio/cvi/include/ansi/setjmp.h"
Header 0014 = "/c/MeasurementStudio/cvi/include/ansi/signal.h"
Header 0015 = "/c/MeasurementStudio/cvi/include/ansi/stdarg.h"
Header 0016 = "/c/MeasurementStudio/cvi/include/ansi/stddef.h"
Header 0017 = "/c/MeasurementStudio/cvi/include/ansi/stdio.h"
Header 0018 = "/c/MeasurementStudio/cvi/include/ansi/stdlib.h"
Header 0019 = "/c/MeasurementStudio/cvi/include/ansi/string.h"
Header 0020 = "/c/MeasurementStudio/cvi/include/ansi/time.h"
Header 0021 = "/c/MeasurementStudio/cvi/include/userint.h"
Header 0023 = "/c/MeasurementStudio/cvi/instr/hm7044/hm7044ui.h"
Max Header Number = 23
 
[Create Executable]
Executable File_Debug = "/c/MeasurementStudio/cvi/instr/hm7044/hm7044_dbg.exe"
Target Creation Date_Debug = 3189076476
Force Creation of Target_Debug = False
Executable File_Release = "/c/MeasurementStudio/cvi/instr/hm7044/fieldpoint.exe"
Target Creation Date_Release = 0
Force Creation of Target_Release = True
Icon File = ""
Application Title = "hm7044 driver"
DLL Exports = "Include File Symbols"
DLL Import Library Choice = "Gen Lib For Current Mode"
Use VXIPNP Subdirectories for Import Libraries = False
Use Dflt Import Lib Base Name = True
Where to Copy DLL = "Do not copy"
Add Type Lib To DLL = False
Include Type Lib Help Links = False
Type Lib FP File = ""
Type Lib Guid = ""
Uses DataSocket = 0
Uses NIReports = 0
Uses DCom95 = 0
Instrument Driver Support Only = False
 
[External Compiler Support]
UIR Callbacks File Option = 0
Using LoadExternalModule = False
Create Project Symbols File = True
UIR Callbacks Obj File = ""
Project Symbols H File = ""
Project Symbols Obj File = ""
 
[DLL Debugging Support]
External Process Path = ""
 
/cvi/instr/hm7044/hm7044ui.h
0,0 → 1,40
/**************************************************************************/
/* LabWindows/CVI User Interface Resource (UIR) Include File */
/* Copyright (c) National Instruments 2005. All Rights Reserved. */
/* */
/* WARNING: Do not add to, delete from, or otherwise modify the contents */
/* of this include file. */
/**************************************************************************/
 
#include <userint.h>
 
#ifdef __cplusplus
extern "C" {
#endif
 
/* Panels and Controls: */
 
#define PANEL 1
#define PANEL_CMD 2
#define PANEL_TEST 3 /* callback function: TestCB */
#define PANEL_SEND 4 /* callback function: Send */
#define PANEL_READ 5
#define PANEL_EXIT 6 /* callback function: Exit */
#define PANEL_PORT 7
 
 
/* Menu Bars, Menus, and Menu Items: */
 
/* (no menu bars in the resource file) */
 
 
/* Callback Prototypes: */
 
int CVICALLBACK Exit(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
int CVICALLBACK Send(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
int CVICALLBACK TestCB(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
 
 
#ifdef __cplusplus
}
#endif
/cvi/instr/hm7044/hm7044ui.uir
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property