02-09-2009 01:08 PM
I would like to send commands to my instrument thru a serial port. Specifically, I would like to send a (CTRL-U) to the THR port, then send 1024 bytes of ASCII, then send another (CTRL-U). I am unfamiliar with serial ports, and confused as to how to accomplish this task. My botch job is attached. Can someone straighten me out please?
Thanks!
02-09-2009 01:40 PM
02-09-2009 01:57 PM
I'm doing it right? That's kind of a bummer. I thought it was operator error. My instrument is not responding correctly. There is something else I can check... If it doesn't work, I'll be back with more details.
Thank you for your quick response.
02-09-2009 04:37 PM
You are explicitly unasserting DTR and RTS in your VI, is this required by your instrument? Sometimes when devices require software-handshaking using the modem lines, you may need to add a small delay before you transmit data. This will ensure that these lines have time to be set on the serial port and be recognized by your instrument before you start sending data.
-Jason S.
02-09-2009 05:18 PM
02-09-2009 05:53 PM
I'm back. I had a few more commands to try, but still have trouble. Here is what I am told...
All comands to be sent thru the THR port
CTRL-U - toggles the instrument into a mirror where it simply reflects bytes that are written. this is how I am supposed to write my ASCCI header metadata info.
CTRL-Y - begins recording data to memory, prepends 1024 bytes ASCII to binary file then starts logging.
CTRL-Z - ends all data recording
So the order of commands I need to send are:
1. CTRL-U (turn instrument into mirror)
2. CTRL-Y (begin data record to disk)
3. send 1024 bytes of ASCII
4. CTRL-U
5. Add button that allows for a CTRL-Z
I am unclear about this Asserted/Unasserted business. Previously, I had to turn DTR and RTS States to Unasserted to write to them, and then turn them back to Asserted, but I am uncertain of what this does. All of this is contained in a while loop. Do I need to Unassert DTR and RTS *every* time I use a VISA Write command to send the command to the THR port? Code attached.
02-09-2009 06:47 PM - edited 02-09-2009 06:48 PM
Normally, you don't have to do anything with the control lines. If you select handshaking, it's done for you by the driver. Trying to do it manually is probably just going to mess up the precise timing and confuse the instrument at the other end.
Sometimes, the instrument does require you to manipulate the control lines. Could you post the manual so that someone can see what it says?
02-09-2009 10:00 PM
Normally, you don't have to do anything with the control lines. If you select handshaking, it's done for you by the driver. Trying to do it manually is probably just going to mess up the precise timing and confuse the instrument at the other end.
Handshaking has been necessary for me for at least one other task (turning on a magnetometer light thru the serial port) while some functions have not required manual handshaking. I assume that since the previous instrument code specifies the THR port that handshaking is necessary. I will test it once I get the syntax correct. But first...
1. If I use manual handshaking, is it necessary to manually set the Property Nodes DTR and RTS States to Unasserted every time I use a VISA Write command as is performed in the True case statement in the most recent code attachement (LVSupport.vi)?
2. If the answer to (1) is yes, when I wish to no longer send data thru the serial port, must I Assert the DTR and RTS States in order to close the port? (I had to do this last time with my command to turn the magnetometer light on and off.)
3. If I do need to have a small delay after handshaking, is there a general rule of how long or is it instrument or baud rate dependent?
Sometimes, the instrument does require you to manipulate the control lines. Could you post the manual so that someone can see what it says?
There is no manual for this instrument. I am copying here some documentation sent to me by the original author of the FORTH code I am trying to replace. For the record, whoever reads this, this is copyrighted material for a patented instrument called the NIMS. You would be crazy to want to steal this code anyway.
The Goal: to prepend 1024 ASCII characters to a binary file that writes to disk.
Thanks for the help!!
02-09-2009 10:01 PM
Too many characters for the last message. Referenced author documentation....
: p? begin 3f8h 5 + p@ ( get byte from line status register LSR )
20h and 0= not until 300 0 do loop ; ( test for THR, TSR
empty )
: headermode ." enter headermode" cr ^u 3f8h p!
50 0 do loop ;
: headermodeoff ." terminate headermode " p? ^u 3f8h p! ." complete" cr
." any key to leave header write operation... " key drop ;
: headerwrite begin key dup ^u = if sp! 1
else 3f8h p! s.rcv emit sp! 0 endif
until 7 emit headermode mm ;
: openheader cr ." open header.tmp " cr ; openheader
a000h 1024 00h fill file1 openf header.tmpfill 1024 bytes beginning at A000h with 00h, then open file header.tmp
a000h 1 1 r/w closef ( get header into memory )read up to 1024 bytes from header.tmp to address A000h, then close file
: sendfile ." transmit header.tmp" cr[another text message]
1024 0 do a000h i + c@ ^z = if 20h a000h i + c! endif loop[scan buffer for CTRL-Z, replacing them with blanks. CTRL-Z is
1024 0 do a000h i + c@ dup emit dup 00h =
if drop leave ." end-of-file character found" cr
else p? 3f8h p! endif loop ; ( send 1kbyte from
memory )1024 0 do start of do loop
: "log ." start compact flash log" cr ;[another WTTS]
p? headermode "log p? ^y 3f8h p! sendfile headermodeoff 0h gop? look for empty THR
02-10-2009 05:09 PM - edited 02-10-2009 05:11 PM
Hello CodeMunkee,
In regards to the DTR and RTS lines, these are used for hardware handshaking. The Serial Communication Overview DevZone article has a simple explanation of how this works.If your hardware requires hardware handshaking, you can configure VISA to control these lines, by using the VISA Configure Serial Port VI as shown in the attached example. Setting Flow Control to anything but None gives control of these lines to VISA, so you will not be able to set or clear them manually.
- If you are using manual flow control, there is no need to re-unassert these lines everytime. You have control over these lines, so the VISA drivers will not change the value of these lines.
- In most cases, when the DTR and RTS lines are unasserted, this means the port is 'turned off' for receiving. This is because the transmitter on the other end will check these lines before they send data and if they are both lowered, then it will not be clear to send data.