|
I am trying to write an array of Bytes to a serial port. If I do the following code I can successfully communicate with the serial port.
Dim byteQuit() As Byte = {&H2, &H51, &H3, &H63, &H8D}
serialPort.Write(byteQuit, 0, byteQuit.Length)
But I want to bring in data and place it in the array. When I do this I get an error 'Out of Bounds Exception'
Dim arrayTemp(10) As String
Dim custByte() As Byte = {&H2, &H45, &H41, &H1, Byte.Parse(arrayTemp(0)), &H1, Byte.Parse(arrayTemp(1)), &H1, Byte.Parse(arrayTemp(3)), &H1, &H1, Byte.Parse(arrayTemp(2)), _
&H1, &H1, &H1, &H1, Byte.Parse(arrayTemp(9)), &H1, &H1, &H1, &H1, &H1, &H1, &H3}
It is obvious that I am doing something wrong with the data conversion. What is not obvious (at least to me, right now) is how to fix it. Granted, if I take the time I could probably figure it out (two weeks later). I was hoping one of you nice people would help me out.
Specifically, how to change arrayTemp() to each Hex character.
Thank you for your help.
|
|
|
|
|
Hi Cory,
obviously there is some code missing that sets the values of arrayTemp.
Just declaring an array, results in a lot of null references, not meaningful data.
Are you saying arrayTemp is holding hexadecimal strings ? if so, Byte.Parse will not
do it in that way ?
Or are you saying your code is an attempt to deal with hexadecimal ? If so, I don't
recognize any of it.
Anyway, I am puzzled by all these &H1 values in custByte().
And I would suggest you do the parsing in separate lines, with intermediate variables;
this would:
- make things more readable,
- allow you to see (even print) the values for inspection,
- allow exact pin-pointing of the exception.
Also please read and apply my sig (tips 1 and 2).
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I already searched articles and google with no result.
In answer to your questions:
arrayTemp holds strings (They don't need to be) like customer#, customer name etc.
To send through a serial port I have to create a frame. &H1 separates the segments of data. The data is hex characters. &H2 starts it and &H3 ends it.
I want to grab data from somewhere and place it in my custByte(). See original post.
EX: Convert the arrayTemp(0) = "1000" to it's hexidecimal equivalent = 31 30 30 30 \
Is there an easy way to do this? Or Hard? I just need to know how this can be done.
|
|
|
|
|
Hi Cory,
you are confusing hexadecimal with decimal, and binary with text.
also your sequence of &H1 does not fit the needs.
31 30 30 and 30, when taken as hex numbers are the values of the ASCII characters 1 0 0 and 0.
Hence you want to send the text string 1000 here. Your code does not do that at all.
So it sounds like you want to send a big string consisting of:
- maybe some initial characters or bytes indicating the start
- then for each field: a starting char or byte, followed by the string representing the value
- maybe some final characters or bytes indicating the end
If all chosen delimiters were printable characters, it would be a plain text application,
and you could solve it with string concatenation, then a single "write string".
If you really need non-printable chars/bytes in between the fields, you can go two ways:
- try to come up with a byte array that contains all; that's the hard way, which you are
attempting right now
- just issue a couple of SerialPort.Write methods, something like (pseudo-code !):
port.Write(aByteArrayIndicatingStart,0,itsLength) ' that is binary operation
for every field:
port.Write(aByteArrayIndicatingFieldSeparator,0,itsLength) ' that is binary operation
port.Write(field.ToString() ' that is text operation
port.Write(aByteArrayIndicatingEnd,0,itsLength) ' that is binary operation
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
How do I ping another computer?
Ross
|
|
|
|
|
There is a nice little Ping class for that...
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
There is is 2.0 but not in 1.1 iirc.
|
|
|
|
|
correct.
Long time ago I did if for 1.0 with some 100 lines of code, using Socket.SendTo
and Socket.ReceiveFrom in a separate thread.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
System.Net.NetworkInformation.Ping
or
My.Computer.Network.Ping()
The second one only returns a boolean value whether or not the ping succeeded.
You'll have to tweak it a bit to make it work.
I made an app that does the same thing "ping Google.com" does in command prompt. I can get you the basics if you wish.
|
|
|
|
|
`Drew wrote: System.Net.NetworkInformation.Ping
well that's 2.0 also
`Drew wrote: My.Computer.Network.Ping()
I do almost everything using C#, and it does not have that nice My thingy.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Luc Pattyn wrote: `Drew wrote:
System.Net.NetworkInformation.Ping
well that's 2.0 also
Is that bad? I'm running 3.5 beta on my Vista machine.
Luc Pattyn wrote: `Drew wrote:
My.Computer.Network.Ping()
I do almost everything using C#, and it does not have that nice My thingy.
Hmm, I'm glad I'm stuck with VB.NET. What is the C# equal to My.settings?
|
|
|
|
|
`Drew wrote: well that's 2.0 also
Is that bad?
No, but my first answer was the Ping class, which got commented as being 2.0
`Drew wrote: I'm glad I'm stuck with VB.NET. What is the C# equal to My.settings?
Most of the things VB collected under My are available in all CLR languages, but not
through an equivalent for My. Total Physical Memory is one of those things only VB's My
offers. If you need to know how to do settings in C# I suggest you read MSDN about that.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
hello friends.!!
i want to scroll or move text in my project to display the latest news but i dnt knw hw i will do tht is there any control in vb.net like in vb 6 marquee ???
plz help n tel me hw i will move or scrool text
thnks in advance
~~~Charanjot~~~
|
|
|
|
|
cnthlpyddntndrstndsnglwrdysd
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi every one. Please help.
I am connecting to a database via a webservice and it works great..
but then i have to connect my GUI via my codebehind page to the webservice and then i get this error.....
Everything works at home on a stand alone computer but not here at college on a networked computer. Can anyone tell me why and what i can do to fix it? Thanks
--------------------------------------------------------------------
error attached
--------------------------------------------------------------------
No connection could be made because the target machine actively refused it
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it
Source Error:
Line 61: string theight,
Line 62: string tphoto) {
Line 63: object[] results = this.Invoke("InsertClient", new object[] {
Line 64: tfirstName,
Line 65: tlastName,
Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\web page\c818c298\b074d3c7\App_WebReferences.qyhgim7u.1.cs Line: 63
Stack Trace:
[SocketException (0x274d): No connection could be made because the target machine actively refused it]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +200
System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) +60
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +579
[WebException: Unable to connect to the remote server]
System.Net.HttpWebRequest.GetRequestStream() +732
System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +176
localhost.WebServ.InsertClient(String tfirstName, String tlastName, Int32 tidNumber, String taddress, String tpostalCode, String tcellPhone, String temail, String tpassword, String tusername, String tquestion, String tanswer, String tgender, String thair, String teyes, String tethnic, String theight, String tphoto) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\web page\c818c298\b074d3c7\App_WebReferences.qyhgim7u.1.cs:63
Reg.cmdSubmit_Click1(Object sender, EventArgs e) in C:\Documents and Settings\craig\Desktop\Web Page\reg.vb:70
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +96
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +116
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3839
|
|
|
|
|
Please don't cross post.
---
single minded; short sighted; long gone;
|
|
|
|
|
Do not cross post. Your small code snippet says you're using C#. Post the question there and stick with that forum.
|
|
|
|
|
Hi guys n gals .....
i need ur help... actly i want to set app(application path) for picture. i m using picture in my project n whnever i chnge the drive i.e. chnge frm one drive to another i hve to chnge the picture path also in code so tht it will be visible whn i run it.....so smebdy tel me hw i set the app path tht paicture so the whn drive chnge it will fetch path automatically plzzz plzzz plzzz help me
thnks in advance
~~~Charanjot~~~
|
|
|
|
|
Application.StartupPath will give you the current location of your Exe
good luck
|
|
|
|
|
Hello Friends,
I want to know How to freeze a particular column in flexgrid .
Eg.
I want to freeze a first column while horizontal scrollbar is used.
how to freeze it.
Give a example
pls Urgent
Thanks
Kankeyan J
|
|
|
|
|
Please read forum guidelines before posting a question.
Here is the link for same Forum Guidelines.
If you google this question you can find the answer.
|
|
|
|
|
hi frnds..
i used to draw the menu's using the draw item & measured item events.. & its nice..but the pblm is how can i give shortcut for that menu items...
|
|
|
|
|
if the menu is of the type toolstripmenuitem you can do it like this:
Dim mnuzoeken As New ToolStripMenuItem("zoeken")
mnuzoeken.ShortcutKeys = CType((System.Windows.Forms.Keys.Control Or System.Windows.Forms.Keys.F), System.Windows.Forms.Keys)
|
|
|
|
|
were i can find the toolstripmenuitem class
|
|
|
|
|
Public Class ToolStripMenuItem
Inherits System.Windows.Forms.ToolStripDropDownItem
Member of: System.Windows.Forms
|
|
|
|
|