Jump to content

Communication via com port


Recommended Posts

I have a remote temperature sensor that I am trying to monitor via the COM port. I have successfully written code in LabView that will do this but would like to perform this inside of an AutoIt script. Below is the code and console responses I have for AutoIt. As far as I can tell I am successfully accessing the COM port but beyond that it does not appear that it is working. The temp reading should be around 25c. Any help regarding this issue is greatly appreciated.

;Define variables
Dim $h_instr = _viOpen("ASRL1::INSTR")
ConsoleWrite("Instrument Handle obtained" & @CRLF & "$h_instr = " & $h_instr & @CRLF) ; Show the Session Handle

_viSetAttribute($h_instr,$VI_ATTR_ASRL_BAUD,9600)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : _viSetAttribute($h_instr,$VI_ATTR_ASRL_BAUD,9600) = ' & _viSetAttribute($h_instr,$VI_ATTR_ASRL_BAUD,9600) & ' - - >Error code: ' & @error & @crlf) ;### Debug Console

_viSetAttribute($h_instr,$VI_ATTR_ASRL_DATA_BITS,7)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : _viSetAttribute($h_instr,$VI_ATTR_ASRL_DATA_BITS,7) = ' & _viSetAttribute($h_instr,$VI_ATTR_ASRL_DATA_BITS,7) & ' - - >Error code: ' & @error & @crlf) ;### Debug Console

_viSetAttribute($h_instr,$VI_ATTR_ASRL_PARITY,$VI_ASRL_PAR_ODD)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $h_instr,$VI_ATTR_ASRL_PARITY,$VI_ASRL_PAR_ODD) = ' & _viSetAttribute($h_instr,$VI_ATTR_ASRL_PARITY,$VI_ASRL_PAR_ODD) & ' - - >Error code: ' & @error & @crlf) ;### Debug Console
_viSetAttribute($h_instr,$VI_ATTR_ASRL_STOP_BITS,$VI_ASRL_STOP_ONE)

ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $h_instr,$VI_ATTR_ASRL_STOP_BITS,$VI_ASRL_STOP_ONE) = ' & _viSetAttribute($h_instr,$VI_ATTR_ASRL_STOP_BITS,$VI_ASRL_STOP_ONE) & ' - - >Error code: ' & @error & @crlf) ;### Debug Console

_viSetAttribute($h_instr,$VI_ATTR_ASRL_FLOW_CNTRL,$VI_ASRL_FLOW_NONE)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $h_instr,$VI_ATTR_ASRL_FLOW_CNTRL,$VI_ASRL_FLOW_NONE) = ' & _viSetAttribute($h_instr,$VI_ATTR_ASRL_FLOW_CNTRL,$VI_ASRL_FLOW_NONE) & ' - - >Error code: ' & @error & @crlf) ;### Debug Console

dim $s_answer = _viExecCommand($h_instr,"*V01" & @CRLF,10000) ; 10 secs timeout
ConsoleWrite("<Temperature is <" & $s_answer & ">" & @CRLF)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : _viExecCommand($h_instr,"*V01" & @CRLF,10000)) = ' & _viExecCommand($h_instr,"*V01" & @CRLF,10000) & ' - - >Error code: ' & @error & @crlf) ;### Debug Console

Instrument Handle obtained
$h_instr = 23345736
@@ Debug(27) : _viSetAttribute($h_instr,$VI_ATTR_ASRL_BAUD,9600) = 0 - - >Error code: 0
@@ Debug(30) : _viSetAttribute($h_instr,$VI_ATTR_ASRL_DATA_BITS,7) = 0 - - >Error code: 0
@@ Debug(33) : $h_instr,$VI_ATTR_ASRL_PARITY,$VI_ASRL_PAR_ODD) = 0 - - >Error code: 0
@@ Debug(36) : $h_instr,$VI_ATTR_ASRL_STOP_BITS,$VI_ASRL_STOP_ONE) = 0 - - >Error code: 0
@@ Debug(39) : $h_instr,$VI_ATTR_ASRL_FLOW_CNTRL,$VI_ASRL_FLOW_NONE) = 0 - - >Error code: 0
<Temperature is <0>
@@ Debug(43) : _viExecCommand($h_instr,"*V01" & @CRLF,10000)) = 0 - - >Error code: 0

Thanks,

James

Link to comment
Share on other sites

post-40573-1271959174633_thumb.jpgThis is a valid command and comes straight from the manual for the unit. This is the same command I use with the LabView program and even have to add the return. To that end I have tried appending @CRLF, @CR, and ^m to the *V01 command but have had no luck within AutoIt. Now as to whether this is a Query, in the strictest since I do not believe so as the question mark is not used when I perform this operation in LabView. I have attached a screen capture of the LabView GUI in case that helps.

Thanks for taking an interest in this

James

Link to comment
Share on other sites

post-40573-1271959174633_thumb.jpgThis is a valid command and comes straight from the manual for the unit. This is the same command I use with the LabView program and even have to add the return. To that end I have tried appending @CRLF, @CR, and ^m to the *V01 command but have had no luck within AutoIt. Now as to whether this is a Query, in the strictest since I do not believe so as the question mark is not used when I perform this operation in LabView. I have attached a screen capture of the LabView GUI in case that helps.

Thanks for taking an interest in this

James

Possibly not many people , certainly not me, have experience using the labview interface to a serial port using AutoIt. There are a couple of COM port udfs in example scripts although it would require learning a new approach. There is a link to my udf in my signature and the first post of the thread has links to the udf download and a rather simple example. It could be that the simple example, which is a limited terminal emulater, might get some respnse for you and if so it could be worth pursuing.
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

People already have connected temp sensors on COM ports using AutoIt. As Martin said, this is a more pedestrian way, but it can help, even only temporarily.

I have a small lab will lots of GPIB intruments that I control with the Visa interface (a very primitive non-payware version) over a slow dedicated Ethernet branch. But I only need to deal with GPIB stuff directly and never had to launch Labview, simply install the NI drivers for networked GPIB ENETs 10 & 100. It would be pointless anyway, since I only do repair and calibration. My calibration procedures are in AutoIt, not LabView. I'm currently very busy with completely other stuff, so that lab is currently power off.

I'm afraid I can't help you much on this. I'll try to re-power a few things to see if I can be of help but I don't promise much.

Edit: I've reinstalled drivers. Everything I can power up (wife sleeping nearby) works but I couldn't find instrument drivers for the only serial instruments I have handy (Thunderbolt GPS timebases) and I ain't in the mood of developping such driver anytime soon.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...