Page 1 of 1
Is it me or am i going crazy
Posted: Thu Mar 18, 2010 7:26 pm
by goldwingers
Hi All
Just got another ECIO40, put in a simple input portB (all) to give a Byte output.
as
loop
input port B
sendbyte
endloop
I am inputting the byte into VB2008 but the returned byte is not as expected in such....
Sw 1 return 1
sw 2 returns 2
sw 3 returns 4
sw 4 returns 8
sw 5 returns 10 - expected 16
sw 6 returns 20 - expcted 32
sw 7 returns 40 - expected 64
sw 8 returns 80 - expected 128
Any ideas?.
Re: Is it me or am i going crazy
Posted: Fri Mar 19, 2010 12:22 pm
by Benj
Hello it looks like you are getting a hexadecimal output.
0x10 = 16
0x20 = 32
0x40 = 64
0x80 = 128
So the values you are getting are indeed correct.
Try holding down switches 3 and 4 and you will notice that the value changes from 4 or 8 to C which is 4 + 8.
Re: Is it me or am i going crazy
Posted: Fri Mar 19, 2010 4:48 pm
by goldwingers
Hi Benj
OK but I am sendibg this out as a byte, why does it change to hex.
I will try this against a program I wrote for hex numbers and see what happens
Cheers
Ian
Re: Is it me or am i going crazy
Posted: Fri Mar 19, 2010 5:24 pm
by Benj
Hello Ian,
It must be that VB is doing something strange when outputting the numbers. That is if you are simply sending the number as a byte. As far as I know you should be able to print out the number directly without modification to allow it to be printed out as decimal. Post up your VB code for the collection and outputting of the value if you like and I will see if I can spot the problem.
Re: Is it me or am i going crazy
Posted: Fri Mar 19, 2010 5:38 pm
by goldwingers
Hi Benj,
'Data breakout
Public Sub DataRx()
While (SerialPort1.BytesToRead > 0)
TextBox1.AppendText(SerialPort1.ReadByte().ToString("x3"))
porta.Text = Microsoft.VisualBasic.Mid(TextBox1.Text, 1, 3)
portb.Text = Microsoft.VisualBasic.Mid(TextBox1.Text, 4, 3)
portc.Text = Microsoft.VisualBasic.Mid(TextBox1.Text, 7, 3)
Portd.Text = Microsoft.VisualBasic.Mid(TextBox1.Text, 10, 3)
Porte.Text = Microsoft.VisualBasic.Mid(TextBox1.Text, 13, 3)
'A0.Text = porta.Text
'a1.Text = portb.Text
'a2.Text = portc.Text
'a3.Text = Portd.Text
'a4.Text = Porte.Text
'a5.Text = Microsoft.VisualBasic.Mid(TextBox1.Text, 31, 3)
End While
End Sub
Re: Is it me or am i going crazy
Posted: Fri Mar 19, 2010 5:50 pm
by Benj
Hello,
Im not sure if this will work in your version of VB but this command should convert a hexadecimal value into a decimal value ready for printing out.
Variable = Format$(Variable)
Re: Is it me or am i going crazy
Posted: Fri Mar 19, 2010 5:53 pm
by goldwingers
Thanks Benj
Sorted it out, The ECIO is sending Hex rather ascii. changed code to suit and now i can extract all 5 ports.
Now more coding
