Sending COM data with a SCRIPT
The bVT100 devices will reflect what is sent to them via the COM port. This article will describe a method whereby a text file can be created and then sent to any serial device using a simple C program called 'scom.exe' This program will work with any device that accepts serial data and thus the USB to I2C converter (BV4221) will also work with this program and therefore I2C devices can be controlled via a simple script.
The current version is v3 and can be obtained in the downloads section.
What is It
scom is a small program written in C that will input a script file and output to the specified COM port. It has been kept as simple as possible so that C programmers can modify the content. Version 1&2 only have 2 commands so they may be the easiest to modify. The most difficult part of this program was finding a suitable method of outputting to the COM port without resorting to complex or commercial DLL's.
The solution was in fact on Microsoft's own MSN site but none the less it was very difficult to track down and very little sensible articles exist on writing to COM ports via Windows. This program has been tested on Winnows XP.
Using
If all you want to do is use the program then unzip the scom file and take out the 'exe' file. Connect up a serial device to the COM port and create a script that matches your com port. For higher numbered COM ports, probably greater than 5 or 9 then an obscure and quite stupid syntax is required:
//./COM124
Above is an example yes, that is slash,slash,dot,slash.
The example script file outlines all of the commands but they are also detailed below.
Step by Step
1) extract the zip file into a suitable directory. The zip file contains the C source code, an example script file (extension .txt) and scom.exe. The exe file is designed to run from a batch file or from a DOS prompt.
2) A good way of opening a DOS prompt is to create a shortcut, you will then be able to open it in the current directory rather than the windows directry. Right click in the directory you want the short cut to be in and choose new>shortcut. In the dialog type 'cmd', then next and finish.

3) Right click on the new shortcut and select properties, remove the "%windir%" from the 'Start in:' text box and then click 'Apply' 'OK'

When the shortcut is now double clicked a DOS prompt will be opened and set to the current window.
As an example to run a script called scr1.txt, this is types into the dos box:
scom scr1.txt
Alternative Batch File
A batch file can be created instead of using a DOS box, simply create a text file and rename it so that the extension is .cmd instead of .txt and place this in it:
@echo off
scom scr11.txt
Assuming that the script file is called scr1.txt. To run it simply double click.
For further information about batch files this is a good source: http://www.computerhope.com/batch.htm
Script Commands
Version 3 has has several new commands added and now this program is becoming quite useful. All commands begin with '!' and the '!' must be the first character of that line.
Open a Com Port
The first item of any script file will be this command. It establishes communication with the correct COM port and Baud rate. Version 3 has added the option of hardware handshaking using the RTS/CTS lines.
!open COM5 38400 0
The above example will open COM 5 at 38400 Baud and NO hardware handshake.
!open //./COM16 38300 1
This next example above will open COM16, because it is higher than 5 then it needs the slashes at the front. The '0' (zero) has now changed to a 1 (one) and so hardware handshaking is turned on.
Wait
The program will halt for the period given after the command
!wait 300
The above example will halt the program for approximately 300 ms
Console
The console command added in version 3 makes the program behave as a terminal, anything types into the command prompt will be sent to the device and anything returned will be displayed at the prompt. A number following the console command is the received character value to terminate it.
!console 2
The above console command will make the program behave as a terminal or console to the COM port. To terminate its action CTRL B is used because that will send the value 2 to the command.
Char
Sends a character value to the COM port, it is sometimes difficult to get non-printable values into a text editor and so this command will come in useful in those situations.
!char 13
The above will send CR to the COM port
!char 35 48 49 50
The above will send '#012' to the COM port. Note that this is the only way to send this string as the '#' would have been interpreted as a comment otherwise.
Character Delay
This is a global command and will apply to the whole session unless of course it is used again within the same script. Some devices, particularly the ones that don't use flow control, may need to have a delay inserted between sending each character. This command does that.
!chardel 3
The above will wait 3ms after sending a character.
Wait For
This command will monitor the incoming serial stream and wait until the specified string is received. This command can be very useful but problematic if the string is never received as there is no time out. If the string is not received it will remain in the loop forever. The only way to terminate is CTR-C which will abort the program.
!waitfor "0x42>"
The above command will wait for the string "0x42>" and return from this loop at the point the '>' is received from the string. Note that if the string is never received then it will never return.
Debug
This is not a command but is useful for observing what is going on. To enable debugging use a '1' (or anything at the moment) after the script file on the command line, for example if the script is scr1.txt then:
scom scr1.txt 1
Will run the script in debug mode and print out commands received etc.
How it Works (v1)
As previously mentioned the most difficult part was tracking down a sensible way to use the COM ports within Windows. Although the method is quite straight forward it is not very public knowledge. Basically once the keyword 'CreateFile' can be associated with COM ports the rest is searchable on the net. It is discovering this in the first place. The relevant information about create file is here:
http://msdn.microsoft.com/en-us/library/aa363858%28VS.85%29.aspx
The COM port is opened using a copy (almost) of the function provided in MSN, this is called by an initialise routine that simply sends CR to the bVT100 device to establish the Baud rate. There are only two COM functions used, PUTS (put string) and PUTC (put character). As at the moment bVT100 devices are read only.
PUTC (com_putc) is slightly more involved than simply sending out a character to the COM port. As hardware handshaking is used the CTS line which is an input on the host is monitored before sending a character. The device will put this line high if it is busy and the com_putc() will check this by using GetCommModemStatus(). Only when the CTS line is taken low will it get past this while statement and send the character. The one proviso to this is a counter that is set to a high value and counts down, should the CTS line be permanently stuck on high then the program will not get stuck at this point.
The function 'get_next' will get a line of text from the script ignoring any lines with '#' and only returning the left hand side of '#' if one exists, effectively removing comments from the input. It will also look for ',' and treat this as a new line.
How it Works (v2,3)
This has a simple text interpreter that can recognise commands, further commands could be added to the code if required. A command begins with '!' which must be the first character of the line. The commands implemented in this version are:
Also added to this is a read function which is used to obtain characters from the input stream.
