Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old October 29th, 2003, 10:42 AM
robertsck robertsck is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Oak Ridge, TN
Posts: 3 robertsck User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old October 29th, 2003, 11:34 AM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,715 Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 21 m 37 sec
Reputation Power: 688
Try removing the $ from your function name? Just guessing.

Reply With Quote
  #3  
Old October 29th, 2003, 12:06 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,171 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 1 m 37 sec
Reputation Power: 110
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
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

Reply With Quote
  #4  
Old October 29th, 2003, 12:38 PM
robertsck robertsck is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Oak Ridge, TN
Posts: 3 robertsck User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #5  
Old October 29th, 2003, 01:44 PM
robertsck robertsck is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Oak Ridge, TN
Posts: 3 robertsck User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
//Delete

Last edited by robertsck : October 29th, 2003 at 04:25 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Sending out Bytes over Mscomm


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway