Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Serial Port Communication is not working as intended
Message
From
11/04/2007 15:56:12
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Serial Port Communication is not working as intended
Environment versions
Visual FoxPro:
VFP 6
OS:
Windows NT
Miscellaneous
Thread ID:
01214675
Message ID:
01214675
Views:
55
I'm trying to create a program to open a serial port on Com 2 at 9600baud N81.
The computer on the other end is going to send a string of data then a Carriage Return.
Once the Carriage Return is recieved I wana send a Line of Text from DownloaderHex.TXT then a Carriage return. Then listen to the serial port again and wait for a Carriage Return to be recieved to send the next line of text from DownloaderHex.TXT... till the end of the file.

When the program runs, it just sits there with the hour glass spinning, so I figure its sorta working, and then when I hook another computer up to the serial port and run Hyper Terminal to see if the program is sending any data.. it isnt. I mash some keys in HyperTerminal, and hit Enter and nothing is recieved. I know its not a problem w/ the serial port because when I cancel this program, and open Hyperterminal on both machines, i can type back and forth between the two machines.

Someone PLEASE HELP ME! I CANT GET IT TO WORK
*SET DEFAULT TO curdir()
*set step on
*** downloaderHex.TXT must exist ***
IF FILE('downloaderHex.txt')
   dHex = FOPEN('downloaderHex.txt')   && Open the file
ELSE
   WAIT WINDOW "DownloaderHex does not exist"
ENDIF
IF dHex < 0  &&If less than 0, then there was an error opening the file
   WAIT WINDOW "Error Opening DownloaderHex.txt"
ENDIF

firstLine = FGETS(dHex)  &&get the first line of text from the txt file

*Create an object ComForm.Testcom to reference the serial port
PUBLIC ComForm
   ComForm = CREATEOBJECT('Form')
   ComForm.AddObject("Testcom","Olecontrol","MSCOMMLib.MSComm")
   ComForm.Testcom.CommPort = 2 && Use Comm2, The second Serial Port.
   ComForm.Testcom.Settings = "9600,N,8,1"  && 9.6 Kbaud, No Parity,
                                             && 8 data Bits, 1 Stop Bit
   ComForm.Testcom.PortOpen = .T.  &&opens the Serial Port
   ComForm.Testcom.RThreshold = 1  &&Sets the Serial ports buffer to recieve
                              &&when 1 character is stored

DO WHILE !FEOF(dHex)
IF ComForm.Testcom.CommEvent = 2  &&This is triggered if the RThreshold is reached, which is 1 character
   IF ComForm.Testcom.Input = vbCrLf  &&If a Carriage return is recieved
      ComForm.Testcom.Output = ">[1]" + firstLine + vbCrLf &&sends a line from the Hexfile
      WAIT WINDOW firstLine NOWAIT
   ENDIF
ENDIF
ENDDO
fclose(dHex)
WAIT WINDOW "DONE SENDING ALL LINES FROM DOWNLOADERHEX.TXT" 
Next
Reply
Map
View

Click here to load this message in the networking platform