|
I have been trying for couple of days now to send 1 byte of data through the serial port to a processor. I have tried multiple different coding schemes I see the com port. It seems to send it but as far as I can tell nothing.... I am using a usb to serial converter... My system sees it as COM1 no problem I detect when I tell the program to find serial ports. finds it...
This is the code in question
using com1 as io.ports .serialport=
my.computer.ports.openserialport("COM1")
com1.writeline(hex(data1)
end using
This is just a byte of data that I need to send. Then I need to receive the data on the same port.... I am at my wits end.... I have put textboxes in place to monitor portions of the code and set breakpoints and it walking through the code.. no problem... so I am not sure what is going on...
Any ideas....
Scott
|
|
|
|
|
It's possible that your code may be fine.
Try communicating via Windows HyperTerminal first. That way you can verify that your cabling and serial port settings are correct.
|
|
|
|
|
okay.. my hardware through hyperterminal works just fine.... I get a my led to flash... using com1 as my port....
Scott
|
|
|
|
|
If all I am sending is a byte would it be correct to use serialport.write.method (byte[],int32,int32) where it only one byte....
Scott
|
|
|
|
|
wtfskh wrote: If all I am sending is a byte would it be correct to use serialport.write.method (byte[],int32,int32) where it only one byte.
Yes, that'll work fine. Are you sure you don't have to send an end character to it too? Like an ETX or CR/LF?
Also, are you setting up the Serial Port settings such as baud rate, data bits, stop bits, parity, etc.? I didn't see that code in your original post.
Here's a reference to the SerialPort[^] class documentation on MSDN in case you weren't aware of it. There's a VB.NET example in that doc.
|
|
|
|
|
All I am a sending is one byte of data to another processor that does something and in return I get data from another processor in a different location. The byte of data is an address to a remote station which will use that to send data back after an a/d conversion which will get displayed. It is dedicated system. The programmer for the processor is driving the baud rate I think a bit too slow but he won't speed it up and won't let any one see his actual code.
I have to thank you.. I have been looking for that documentation for about 2 days now. I didn't put that up but yes I have set baudrate, databits, stop bits = 1200, 8, 1. No parity, no handshaking.. I realized tonight that I wasn't opening up the com port as part of my code about 615. I went on a mad search to find the correct syntax.. very hard to find. The class documentation shows me the correct the syntax. This is for a senior project that is due by the end of next week for senior design show.
I was using vb6 but after I realized that some of the code I was trying to write didn't have documentation behind it so I (within the last 2 weeks) upgraded to vb 2005 express.... most of the code imported pretty good there were only a few minor changes that needed to made to get the rest of it work correctly..
Scott
|
|
|
|
|
Sounds like a good project. A very realistic experience.
If it works with HyperTerminal, then there's no reason why it shouldn't work with your app. There must be a bug somewhere.
We need to verify that your app is actually sending a byte out of the serial port. An easy way to do this is to connect your COM1 to your PC's COM2 if you have one. If you don't have another COM port, then connect it to another PC's COM port. Next, launch HyperTerminal that's setup for that other COM port. Then you should launch your app and verify that its bytes are appearing in HyperTerminal. If the bytes are showing up, then your transmission is working fine.
|
|
|
|
|
wtfskh wrote: The programmer for the processor is driving the baud rate I think a bit too slow but he won't speed it up and won't let any one see his actual code.
Hmmm... are you then sure that the 1200/8/1/n setting is correct? Another possibility is the cable you are using to connect to the device is either faulty, incorrectly connected wrt: pinouts or electrically incompatible. (If you are using ribbon cable then you could get all sorts of RFI and wierd signals interfering with the comms. Are the RTS and CTS signals latched to the correct levels?
...Steve
1. quod erat demonstrandum
2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once
|
|
|
|
|
Yes I am sure it is correct because I argued with the firmware programmer to up to speed to at least 19.6k and he won't says it is too fast... We are not using rts and cts... not practicable in the application as it stands. Yes it does work with a small app that the firmware programmer found in VB6, I think, but only sends one byte of data then you have to do to conversion. We are using a standard rs-232 cable the only difference is that I have use a usb to 232 because my laptop didn't come with a straight 232 connection. I did have to update my driver for it it was 3 yrs old and a newer one was available which is two yrs newer than the one I got with the device.
Scott
|
|
|
|
|
I am looking at the code online and all it does is frustrate me... what the hell is instance stand for in a term like this...
Dim instance As SerialPort
Dim buffer As Byte()
Dim offset As Integer
Dim count As Integer
instance.Write(buffer, offset, count)
I would write
dim port as serialport
dim buffer as byte()
dim offset as integer =0
dim count as integer =1
port.write(byte(), offset, count)
|
|
|
|
|
Instance in this context is simply a variable of type SerialPort.
Can you post the exact code (copy & paste) so we can see exactly what's going on?
BTW, the other programmer may be correct in refusing to increase the port speed since the target hardware may not be capable of 19.2kbps. Depends on the design.
...Steve
1. quod erat demonstrandum
2. "Give a man a fish and you've fed him for a day. Teach him how to fish and you've fed him for life." I read that somewhere once
|
|
|
|
|
Included is code I am using to try and get the com port to transmit. I was working on this last night. I am looping the output right back into the input at this time just for testing purposes, and yes I am trying to send the hex value I did commit out some of the stuff that you see because I wasn't sure if I needed it and the reason for using the button is we are activating this on a timer..
Imports System
Imports System.IO
Module Module1
End Module
Public Class Form1
Public Shared Function Hex(ByVal Number As Byte) As String
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GetSerialPortNames()
'dtrenabled = True
Dim baudRate As Integer = 1200
Dim stopbits As System.IO.Ports.StopBits = IO.Ports.StopBits.One
Dim ports As String = "COM1"
Dim databits As Integer = 8
Dim parity As Boolean = False
'Dim com1 As System.IO.Ports.SerialPort = My.Computer.Ports.OpenSerialPort(ports, baudRate, parity, databits, stopbits)
'Console.WriteLine(Bite(0) & Bite(1) & Bite(2))
'Junk to stop the console closing
'Console.WriteLine("Press Enter/Return to close")
'Dim PressEnter As String = Console.ReadLine()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim stopbits As System.IO.Ports.StopBits = IO.Ports.StopBits.One
Dim Synk As Byte = 255
Dim Servo As Byte = 241
Dim MoveIt As Byte = 100
Dim Bite() As Byte = {Synk, Servo, MoveIt}
' Send commands to a serial port
Using com1 As IO.Ports.SerialPort = My.Computer.Ports.OpenSerialPort("COM1", 1200, IO.Ports.Parity.None, 8, stopbits)
com1.Write(Bite(0))
txttransmit1.Text = (Bite(0))
com1.Write(Bite(1))
com1.Write(Bite(2))
End Using
End Sub
Sub GetSerialPortNames()
' Show all available COM ports.
For Each sp As String In My.Computer.Ports.SerialPortNames
cmbcomport.Items.Add(sp)
Next
End Sub
Function ReceiveSerialData() As Byte
' Receive bytes from a serial port.
Dim sname As String
Dim returnStr As String
Dim retdata As Byte
sname = cmbcomport.Text
Using com1 As IO.Ports.SerialPort = _
My.Computer.Ports.OpenSerialPort("COM1")
Do
Dim Incoming As Byte = com1.ReadByte()
If Incoming Like Nothing Then
Exit Do
Else
returnStr &= Incoming
End If
Loop
End Using
retdata = ("returnStr")
txtreceive1.Text = (retdata)
Return retdata
Scott
-- modified at 15:39 Monday 22nd May, 2006
|
|
|
|
|
creating a listbox dynamically and it wont fire the method listed below when the selected index has changed.
not sure why this is not working, here is the code i use.
Dim list As New ListBox
list.ID = "imageList"
list.Width = "300"
list.Height = "200"
AddHandler CType(list, ListBox).SelectedIndexChanged, AddressOf index_changed
list.Items.Add("shipping.jpg")
list.Items.Add("payment.jpg")
list.Items.Add("top_1.jpg")
p1.Controls.Add(list)
Private Sub index_changed(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
|
|
|
|
|
Hi,
In my vb.net application, it seems that the KeyUp events and Timer Tick events cant be processed simulatanously. When I press the Up arrow key, the timer tick event does not seem to work.
Both events move a picturebox control each. The KeyUp events move the picturebox up and down the form while the timer tick event moves another picturebox from right to left at 1 pixel for each tick.
The problem occurs when I press the Up arrow key. The first picturebox moves up and down the screen. But while the Up arrow key is pressed, the other picturebox, controlled by the timer tick event, stops moving.
Only when I release the Up arrow key does the timer tick event resume and start moving the other picturebox across the form.
The line of code for the timer tick event is:
PictureBox10.Location = New Point(PictureBox10.Location.X - 1,
PictureBox10.Location.Y)
The code for the Key Down event consists of 2 while loops to move the picturebox up and down the form. One while loop is shown below:
While ((Form1.PictureBox3.Location.Y > 80) And hitTop = 0)
Form1.PictureBox3.Location = New Point(Form1.PictureBox3.Location.X, Form1.PictureBox3.Location.Y - 1)
If (Form1.PictureBox3.Location.Y <= 80) Or hitTop = 1 Then
hitTop = 1
End If
End While
How do I make both events occur simultanously? e.g when the up arrow key is pressed, one picturebox 'jumps' up and down the form while the timer tick event still moves the other picturebox across the form
|
|
|
|
|
The app's thread can only do 1 thing at a time. This means while you are locked in your KeyDown's while loop, it can't do anything else. This includes timer events, button clicks, etc.
The "quick and dirty" fix for this would be to add a call to Application.DoEvents() inside your While loop. A call to this function will pump all of your form's windows messages that have stacked up. This includes timer events, click events, key press events, draw events, etc.
|
|
|
|
|
Hi, been trying to add code to perform a calculation using Check boxes and Radio buttons and using the If, And, Then and Elseif function statements which do appear to work but I don't think that this is the right way to code for this type of calculation (as it goes on and on with the different types of variables that you could have) but don't understand enough to use the DIM functionilty and wondered if someone could provide an example based on some sample code below:
'The following statements calculate the Price of individual and multi-selected options and volumes
If CheckBox7.Checked And RadioButton1.Checked = True Then
txtResult.Text = 1055 * 1
ElseIf CheckBox7.Checked And RadioButton2.Checked = True Then
txtResult.Text = 1055 * 2
ElseIf CheckBox7.Checked And RadioButton3.Checked = True Then
txtResult.Text = 1055 * 4
ElseIf CheckBox7.Checked And RadioButton4.Checked = True Then
txtResult.Text = 1055 * 8
ElseIf CheckBox1.Checked And CheckBox2.Checked And RadioButton1.Checked = True Then
txtResult.Text = 300 * 1 + 120 * 1
ElseIf CheckBox1.Checked And CheckBox2.Checked And RadioButton2.Checked = True Then
txtResult.Text = 300 * 2 + 120 * 2
ElseIf CheckBox1.Checked And CheckBox2.Checked And RadioButton3.Checked = True Then
txtResult.Text = 300 * 4 + 120 * 4
ElseIf CheckBox1.Checked And CheckBox2.Checked And RadioButton4.Checked = True Then
txtResult.Text = 300 * 8 + 120 * 8
ElseIf CheckBox1.Checked And CheckBox3.Checked And RadioButton1.Checked = True Then
txtResult.Text = 300 + 15 * 1
ElseIf CheckBox1.Checked And CheckBox3.Checked And RadioButton2.Checked = True Then
txtResult.Text = 300 * 2 + 15 * 2
ElseIf CheckBox1.Checked And CheckBox3.Checked And RadioButton3.Checked = True Then
txtResult.Text = 300 * 4 + 15 * 4
ElseIf CheckBox1.Checked And CheckBox3.Checked And RadioButton4.Checked = True Then
txtResult.Text = 300 * 8 + 15 * 8
ElseIf CheckBox1.Checked And CheckBox4.Checked And RadioButton1.Checked = True Then
txtResult.Text = 300 * 1 + 5 * 1
Any Help appreciated.
Thanks
|
|
|
|
|
well sample .. there are billions of samples for coding patteren. and as per your requirement no one can provide you the sample unless he is free to do this. as far your coding is concerned. I dont understand how you work on checkboxes and radio buttons without renaming them. so the tip of the day is that always rename all the controls on the form..... and rename the form as well as
Rizwan bashir
|
|
|
|
|
Hi,
I have created a client/server application using Remoting. Everything works fine until I start another instance of the remoting server, this causes a System.Net.Sockets.SocketException - "Only one usage of each socket address is normally permitted"
So I tried to make the server a Single Instance Application by checking the box in My Project - Properties (I'm using VB 2005)
But now whenever I try to run the server I get a RemotingException - "Authentication Failure". Can anyone tell me why this exception is thrown?
Is there an alternative way to make a single instance application?
Thanks,
dlarkin77
|
|
|
|
|
Exception is coming somewhere in your code
if you can provide us the coding and highlight on which line the exception is coming then it would be much easier. other wise only those can reply who had suffered the same problem and then solved it.
Rizwan Bashir
|
|
|
|
|
Hi,
Thanks for the quick response. I had been calling
ChannelServices.RegisterChannel(channel, False) , changing it to ChannelServices.RegisterChannel(channel, True) sorted it out.
dlarkin77
|
|
|
|
|
Folks,
I am trying to figure out why the following code is not functioning properly. It seems to be failing on the second call to the API call with an 'Object reference not set to an instance of an object.' I think that it does not like one of the input parameter types.
Private Declare Function LookupAccountSid Lib "advapi32.dll" Alias "LookupAccountSidA" ( _
<marshalas(unmanagedtype.lptstr)> ByVal lpSystemName As String, _
ByVal lpSid As IntPtr, _
<marshalas(unmanagedtype.lptstr)> ByVal lpName As StringBuilder, _
ByRef cchName As Integer, _
ByVal lpReferencedDomainName As StringBuilder, _
ByRef cchReferencedDomainName As Integer, _
ByVal peUse As Integer _
) As Boolean
Private Declare Auto Function ConvertSidToStringSid Lib "advapi32.dll" ( _
ByVal pSid() As Byte, _
ByRef ptrSid As IntPtr _
) As Boolean
Private Declare Auto Function ConvertStringSidToSid Lib "advapi32.dll" ( _
<marshalas(unmanagedtype.lptstr)> ByVal StringSid As String, _
ByRef Sid As IntPtr _
) As Boolean
Dim sid As String = "S-1-5-xxxxxx"
Dim pSid As IntPtr = Nothing
Dim accountNameLength As Integer = 0
Dim domainNameLength As Integer = 0
Dim sidUse As Integer = 0
Dim domainName As StringBuilder
Dim accountName As StringBuilder
Dim apiError As Integer = 0
Dim isConverted As Boolean
Dim succeeded As Boolean
Dim returnString As String
Try
isConverted = ConvertStringSidToSid(sid, pSid)
If Not isConverted Then
apiError = Marshal.GetLastWin32Error
Marshal.FreeHGlobal(pSid)
Throw New Exception(New Win32Exception(apiError).Message)
End If
succeeded = LookupAccountSid( _
Nothing, _
pSid, _
accountName, _
accountNameLength, _
domainName, _
domainNameLength, _
sidUse _
)
domainName = New StringBuilder(domainNameLength)
accountName = New StringBuilder(accountNameLength)
succeeded = LookupAccountSid( _
Nothing, _
pSid, _
accountName, _
accountNameLength, _
domainName, _
domainNameLength, _
sidUse _
)
If succeeded Then
Marshal.FreeHGlobal(pSid)
returnString = domainName.ToString & "\" & accountName.ToString
Else
apiError = Marshal.GetLastWin32Error
Marshal.FreeHGlobal(pSid)
Throw New Exception(New Win32Exception(apiError).Message)
End If
Catch ex As Exception
Throw New Exception(ex.Message)
Finally
End Try
|
|
|
|
|
Hello!
I am pretending to write a spyware application with vb.net. However, I don't know how to get the patterns (intelli signatures) of viruses.
Is there a web site who allows visitors to download such pattern files. Would you please let me know if you know a well-known one.
Thanks!
Bedri
|
|
|
|
|
I want to add sizing handles to my image processing aplication, same as they provide on Designer to move and resize objects(control). Please help.
safalmittal@gmail.com
|
|
|
|
|
some calculation is required. like
1. when on image contorl the mouse is on border then change the cursor type to resize.
2. then on mouse down if mousepointer is resize then say one boolean is set to true.
3. then on mouse move the boolean is true then resize the imagebox with current co-ordinates.
hope you will understand.
by the way in image applications user click zoomin and zoomout stuff which you can do by increasing the width and height of the control
Rizwan Bashir
|
|
|
|
|
I have a vb application that generates tha following error:
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
How can I resolve this error?
|
|
|
|