|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Sending out Bytes over Mscomm
Hi y'all
I am attempting to use Mscomm to send out some data over the serial port to a board that I have built. The board has a command that looks like this #XXYY, where # is the ASCII character '#' and XX and YY are Hex bytes 00-FF. The VB program reads a string from a text box. Then takes that value and multiplies by 10. That is converted to hex and masked off into upper and lower bytes. Then it is converted to an integer. The upper and lower bytes are then sent out via Mscomm. Below is my code.. Private Sub SendVBut_Click() Dim A ' Var used to store string from text box as double,incoming Value Dim B ' Var used to store value of string from text box as double Dim C As String 'string holding hex upper hex byte of B Dim D As String 'string holding lower hex byte of B Dim E As Byte 'Byte holding value of upper hex byte B Dim F As Byte 'Byte holding value of lower hex byte B A = Val(VoltageEBox.Text) 'Stores Value of text from box as A) B = A * 10 'Multiplies value by 10 B = Hex(B) 'Converts to hex string C = CStr(B And &HFF00) 'Masks off upper bits D = CStr(B And &HFF) 'Masks off lower bits Hex2Bin$ (D) 'Converts to Lower Binary String Hex2Bin$ (C) 'Converts to upper Binary String E = CByte(Val(C)) 'Converts value of string to upper byte F = CByte(Val(D)) 'Converts value of string to lower byte MSComm1.Output = Chr(35) +Chr(F) + Chr(E) 'outputs bytes via MScomm End Sub Function Hex2Bin$(HexValue$) Const BinTbl = "0000000100100011010001010110011110001001101010111100110111101111" Dim X, Work$ Work$ = "" For X = 1 To Len(HexValue$) Work$ = Work$ + Mid$(BinTbl, (Val("&h" + Mid$(HexValue$, X, 1) - 1) * 4 + 1), 4) Next Hex2Bin$ = Work$ End Function I get an message about an improper function call, what is causing this error? And will the chr() command ouput all ASCII charchters, including the extended ASCII set? If it will not how can I go about sending out all of my commands? Thanks in advance for your help Last edited by robertsck : October 29th, 2003 at 10:45 AM. |
|
#2
|
|||
|
|||
|
Try removing the $ from your function name? Just guessing.
|
|
#3
|
||||
|
||||
|
Hi Rob - How's Oak Ridge? Not planning on hacking any nuclear reserves are you
. Question for you, have you tried communicating with your board using HyperTerminal? I use it at work to rule out Hardware issues with PLC's
__________________
Fisherman "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein |
|
#4
|
|||
|
|||
|
Hi Fisherman
Nah, I work for the DOE so no funny business here.
I have tested the board with hyperterminal as best as I can. The board is a mini High Voltage Power Supply. The voltage as sent as a 16 bit little endian packed number, 10*(MSB,LSB). So some of the numbers used are in the extended ASCII set, 80H - FFH plus control commands. I can use hypertermianl to test the set high voltage command but not to read it, because many of the control charchters do not show up on hyperterminal. |
|
#5
|
|||
|
|||
|
//Delete
Last edited by robertsck : October 29th, 2003 at 04:25 PM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Sending out Bytes over Mscomm |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|