Visual basic Program to use with picaxe

radcom

Member
I am trying to create a command line based program to send serial data to a picaxe 28-X1

The general idea it that I can have a program and I can launch it with different values in the command line which are then sent out the serial port to the picaxe
i.e. launching "myprogram" with the number "123" in the command line will send "123" to the picaxe or having "abc" in the command line will send "abc" to the picaxe all the port and speed setting don't need changing so they can stay fixed inside the program and I can recompile if I need to change them which I don't mind one the string has been sent the program ends itself ready for the next time is it run I have already tried one method of doing this but it doesn't work properly feel free to ask for my vb code if you need it.
 
Last edited by a moderator:

moxhamj

New Member
Yes sure that can be done and there are some links if you like to working vb.net programs eg nhttp://www.instructables.com/id/Control-real-world-devices-with-your-PC/ but you might already have that working anyway which bits do you already have working the vb.net part or the picaxe part and yes if you can post code it will help and then we can work out which needs to be fixed it does help to get code working on a picaxe and then not have to reprogram the picaxe all the time but send some variables to run different picaxe subroutines.
 

radcom

Member
I would prefer to keep to VB 6 using the MSCOMM but may use vb.net if necessary as for the instructable I am actually doing some thing like that (Its what gave me the idea but it has not the way I wanted to do it and it had too few outputs) and already have the web side of thing working and the picaxe end working its just the VB bit in the middle I am struggling with my method is split in 3 sections first the web side second the program in the middle then the picaxe at the end, both the web side and picaxe side are working 100% correctly as I have tested all three independently and they check out.
 
Last edited by a moderator:

radcom

Member
My VB 6 code for the middle bit

Code:
Private Sub Form_Load()
comport = 1
baudrate = 4800
lbl_com.Caption = comport
lbl_baud.Caption = baudrate
MSComm1.Settings = baudrate & ",n,8,1"
If Command <> "" Then Call cmdline
lbl1.Caption = baudrate & ",n,8,1"
End Sub

Private Sub cmdline()
MSComm1.CommPort = comport
MSComm1.InputLen = 0
MSComm1.PortOpen = True
MSComm1.Output = Command
MSComm1.PortOpen = False
End
End Sub

Private Sub Form_Terminate()
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
End Sub
This code works up to sending the number 99 but not 100
 
Last edited by a moderator:

moxhamj

New Member
Well that bit of code looks ok but that isn't the bit that isn't working right because it is the sending 99 vs sending 100 that is the problem so are you sending this as binary or as ascii because if it is binary then the picaxe can read one byte and get a value from 0 to 255 but if you are going to send ascii numbers you will need three bytes to go from 0 to 255 and for numbers like 7 you might need to send that as 007 otherwise the length of the string changes plus there is a bit of a tricky bug in vb where strings don't go over 127 and you need to send as binary but if the value is 100 that probably isn't the issue anyway could you post the bit of code that isn't working because I'm still not sure if the problem is the vb.net code or the picaxe code and also below is an example of some vb6 code
Dim Sum As Long
Dim LSB As Long
Dim MSB As Long
Dim BaudRate As Integer
Dim CommPort As Integer
Dim OutputString As String
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
BaudRate = 1200
CommPort = 2
MSComm1.Settings = Trim(Str(BaudRate)) + ",n,8,1"
MSComm1.CommPort = Trim(Str(CommPort))
Sum = Byte1 + Byte2 + byte3 + Byte4
MSB = Sum \ 256
LSB = Sum Mod 256
OutputString = "DataT" + Chr(Val(DeviceNo)) + Chr(Val(Byte1)) + Chr(Val(Byte2)) + Chr(Val(byte3)) + Chr(Val(Byte4)) + Chr(Val(LSB)) + Chr(Val(MSB))
MSComm1.PortOpen = True
MSComm1.Output = OutputString
MSComm1.PortOpen = False
 

radcom

Member
The code I have posted previously is all the code from my program, the code on the picaxe is very simple and works with terminal programs fine from 0 to 255
Code:
 main:
label_25:       Disconnect
                serrxd #b0
                reconnect
                Let pins = b0   
                sertxd (#b0)
                GoTo label_25
I do have to send a non numerical character afterwards though to make it work at all
 
Last edited by a moderator:

radcom

Member
I am not sure I posted the full code for the VB6 so here it is
Code:
Dim comport As Integer
Dim baudrate As Long

Private Sub cmd_send_Click()
MSComm1.CommPort = comport
MSComm1.InputLen = 0
MSComm1.PortOpen = True
MSComm1.Output = txt_send.Text
MSComm1.PortOpen = False
txt_send.Text = ""
End Sub

Private Sub Form_Load()
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
comport = 1
baudrate = 4800
MSComm1.Settings = baudrate & ",n,8,1"
If Command <> "" Then Call cmdline
lbl1.Caption = baudrate & ",n,8,1"
End Sub

Private Sub cmdline()
MSComm1.CommPort = comport
MSComm1.InputLen = 0
MSComm1.PortOpen = True
MSComm1.Output = Command
MSComm1.PortOpen = False
End
End Sub



Private Sub Form_Terminate()
If MSComm1.PortOpen = True Then MSComm1.PortOpen = False
End Sub

I can send 255 to the picaxe and it work correctly (all the LEDs light up as they should) using this code but I have to send each number individually i.e. 2 <send> 5 <send> 5 <send> space <send> and that works but I have to do it and I have no clue on how to make it all happen automatically I believe I could do it with an array or somthing but I have no idea on how to do so. I have been trying to do this for months on end and now I feel I am on the home stright
 
Last edited by a moderator:

hippy

Ex-Staff (retired)
You can send a single byte value to the PICAXE using -

MSComm1.Output = Chr$(value)

where 'value' is a variable holding the value you wish to send, 0 to 255.

Doing it all automatically you need to largely forget about "forms" but you will need one to hold the serial control (MScomm1). Within "Sub Main", parse the commandline to determine what to send and where to, open the serial port, send your data, close the port then exit the program.

As always, do it incrementally, in stages; get what you have working with byte values, get a command line reporting program working with "Sub Main", add command line parsing, then bring in the actual serial port handling.
 

radcom

Member
I have tried using what you suggested but nothing has happened also isn't Chr$ used for converting ascii to a string which I don't need to do as my data is already in a string, as for the command line bit I can do that and it works as I have done it before with a couple of other programs
 
Last edited by a moderator:

radcom

Member
I have been looking at the terminal demo program you posted here hippy and was wondering how I could modfiy it so instead of getting the data to send from key strokes it would split and send the numbers in the string one by one then adding a non numerical character afterwards
 
Last edited by a moderator:

hippy

Ex-Staff (retired)
You could modify the Terminal Emulator but it's probably far easier to decide what you actually want and do that.

Here's a VB6 program which runs from the command line and sends a single numeric value as specified as a parameter as a single byte. If you use "Send2Axe 123", a PICAXE executing a "SERIN pin,baud,b0" will get the value 123 put into b0.

Download, rename Send2Axe.Zip.Plf to Send2Axe.Zip, unzip.

It should work if the MScomm32 control is installed. Let me know if it gives any peculiar errors when running the .exe file.
 

Attachments

radcom

Member
That would be exactly what I am trying to do if only it would work
when I run it with a value nothing happens no eroors or anything if I run it with out a parameter it throws up the invalid command line error could this be because its not sending the non numeric character
 
Last edited by a moderator:

hippy

Ex-Staff (retired)
When you say "nothing happens" are you sure that's really the case ?

Send2Axe transmits on COM1 at 4800 baud so connect COM1 TX to COM2 RX ( use a null-modem, crossover or LapLink cable or wires pushed in the right holes ) and watch COM2 using the Terminal Emulator at 4800 baud - When you execute "Send2Axe 85" you should see "U" received on COM2.

Alternatively, set a breakpoint in VB6 after the "MSComm1.output=" line, set the Command Line Argument to 85 and run the program. If it hits the breakpoint it's got that far so it's opened the port and has sent a byte.

Did you remove the # from your SERRXD if using a PICAXE ? Otherwise it's still expecting numeric digits, not a byte value.
 
Last edited:

radcom

Member
right I have tested it with a null-modem lead and it does work the only trouble now is that only works for values from 0 to 9 as its sent as a single character
 
Last edited by a moderator:

hippy

Ex-Staff (retired)
When you use "Send2Axe 85" and monitor what's recieved, what does it show ? What are you using to show the received data ?

What command are you using and what do you mean when you say "its sent as a single character"; what is "its" in this case ?
 

radcom

Member
I am sending ascii 85 out of Send2Axe this shows as "U" (only with out the quotes) on terminal I looked up the ascii 85 which is the ascii code for "U" I looked it up at http://www.asciitable.com/
 
Last edited by a moderator:

krypton_john

Senior Member
I am trying to create a command line based program to send serial data to a picaxe 28-X1

The general idea it that I can have a program and I can launch it with different values in the command line which are then sent out the serial port to the picaxe
i.e. launching "myprogram" with the number "123" in the command line will send "123" to the picaxe or having "abc" in the command line will send "abc" to the picaxe all the port and speed setting don't need changing so they can stay fixed inside the program and I can recompile if I need to change them which I don't mind one the string has been sent the program ends itself ready for the next time is it run I have already tried one method of doing this but it doesn't work properly feel free to ask for my vb code if you need it.
No need for any fancy VB code. From command prompt just type
c:> echo abc > com1:
 

radcom

Member
I have just been trying that and although it sends the data out (i've checked it with a null modem lead) nothing happens on the picaxe
 
Last edited by a moderator:

moxhamj

New Member
nothing has happened because the power is not connected or your wires have fallen out or the receiver isn't working or the transmitter isn't transmitting and basically it is very difficult to work out which one of those it might be without more information can you maybe post a picture of your setup so we can see which pins you are using also a schematic plus if you have info already in strings then exactly what sort of string is it two characters long or three characters long because if it is only two characters long then of course it won't be able to send numbers over 99 so maybe describe a bit more which part isn't working and maybe we can help with some little programs for instance that convert strings of different length to strings of fixed length eg I often have to use trim to get rid of the leading space then you add "000" to the beginning of the string and then use right$(mystring,3) to get the rightmost three characters
 

radcom

Member
I have tryed using a string 3 characters long like sending 001 for 1 I am sending the data in using serxd and the picaxe is working as I can send data in using a terminal program
 
Last edited by a moderator:

hippy

Ex-Staff (retired)
I am sending ascii 85 out of Send2Axe this shows as "U" (only with out the quotes) on terminal I looked up the ascii 85 which is the ascii code for "U" I looked it up at http://www.asciitable.com/
That shows the Send2Axe program is working and doing as is expected.

I have tryed using a string 3 characters long like sending 001 for 1 I am sending the data in using serxd and the picaxe is working as I can send data in using a terminal program
How are you sending 001 using a terminal program ? If as three typed characters "0", "0" and "1" that suggests the PICAXE program is expecting three digits or using "SERRXD #var" to read the number. If that's so then, no, it will not accept single byte data sent by Send2Axe.

The problem seems to be in that the PICAXE is either not receiving the data, is not written to receive byte data, or isn't handling what is received correctly. Post the code you are currently and actually using and the second issue can be answered.
 

radcom

Member
A Better explanation of my situation

The set-up:
It?s a picaxe 28X-1 on a rev-ed project board each of the 8 outputs is connected to a LED so that each can be set by let pins = so to turn all the LEDs on its let pins = %11111111 or let pins = 255 to turn them all off its let pins = %00000000 or let pins = 0 and to turn the first output on its %00000001 or let pins = 1 and to set the pins to a value stored in a variable let pins = b0

The code is:
Code:
 main:
label_25:       Disconnect
                serrxd #b0
                reconnect
                Let pins = b0   ' %00000000
                sertxd (#b0)
                GoTo label_25
Now using this code works with the Serial Comms Example hippy posted here as long as I also put the non-numeric character at the end: http://www.picaxeforum.co.uk/showthread.php?t=8011 , it also works with the terminal in the programming editor if I send each digit individually i.e. to send 255 I have to send it as 2 (press send), 5 (press send), 5 (press send), f (press send) and that works perfectly.

Sending 1 or 2 digit numbers: People in previous posts suggested I only send 1 as 001
But this has no difference than sending 1 as 1 or 001 as long as I include the non-numeric character at the end.

Removing the # from serrxd #b0 to make it serrxd b0 just make the picaxe set the pins to the ascii number the for the characters I just sent i.e. sending the digit 1 sets the pins to 49 which I know is the ascii number for 1 and then I send 2 digit numbers i.e. 10 it sets the outputs to first 49 then 48 (ascii for 1 = 49 ascii for 0 = 48) this is also true for 3 digit numbers only instead of changing twice it changes 3 times i.e. sending 123 set the outputs to first 49 then 50 then 51 (as ascii: 1 = 49, 2 = 50, 3 = 51) the trouble with that to set the outputs to what I want them set to I would have to send the right ascii character but there are a number of ascii values which can?t be displayed or sent like ascii 6.


I hope this explains things better as have I been in a rush before with other things and not have chance to properly explain.

edit: This only needs to work with values from 0 to 255 no bigger or smaller and no letters
 
Last edited by a moderator:

moxhamj

New Member
Ah, I get it. So you want to send ascii character 6 and have the leds light up 00000110?

Nothing wrong with the picaxe code. Just leave out the #.

The issue is with the terminal end. I don't think you can send ascii character 6 very easily from the terminal. But maybe there is a way.

But you are writing vb6 code, not terminal code. So in vb6

MSComm1.Output = chr(6)
 

radcom

Member
Ah, I get it. So you want to send ascii character 6 and have the leds light up 00000110?
Its not the ascii I want to send Is the number 6 which is ascii number 56 I only mentioned sending ascii 6 as a problem in sending the ascii as if you look it (ascii number 6) up somewhere like here http://www.asciitable.com/ you find the character it represents is "ACK" for use with an dialup modem I think

quick note on something I discovered
if I send 56 it doesn't give 6 it gives 53 then 54 as 56 is split in to 5 and 6 as ascii for 5 = 53 ascii and for 6 = 54 and sending 53 and 56 split into 4 more ascii codes 5,3,5,6 which would give ascii values of 53,51,53,54 and this would go one until something give up as the number of digits doubles each time i.e. 1 to 2 to 4 to 8 to 16 and so on.

What I think it may need is to convert the ascii code back into whatever it represented in the first place i.e. the number 6 becomes ascii 56 and is converted back from ascii 56 to the number 6 on the picaxe only how would this work for 2 and 3 digit numbers like sending 13 or 123 or 255?

the sertxd command can be ignored as thats just reading back the value of b0 and since let pins = b0 sets the output pins to what ever value is in b0 sertxd is useful to have
________
Arizona Medical Marijuana Dispensary
 
Last edited:

hippy

Ex-Staff (retired)
I hope this explains things better as have I been in a rush before with other things and not have chance to properly explain.
You need to explain what you want; exactly what you want.

Forget what has gone, ignore what happens with what you already have, forget about ASCII terminology ( it's being misunderstood, misused and is confusing things ), put aside HyperTerm and the Terminal Emulator.

With the following code running on a 28X1 and LED+R's on output pins 0-7 to 0V ( which I'll call LED 0 to LED 7 ) ...

Code:
Disconnect
Do
  SerRxd b0
  pins = b0
Loop
Send2Axe 1 - Turns on LED 0, all others off, SendAxe 001 does the same
Send2Axe 2 - Turns on LED 1, all others off
Send2Axe 3 - Turns on LED 0 plus LED 1, all others off
Send2Axe 128 - Turns on LED 7, all others off
Send2Axe 255 - Turns all LEDs on
Send2Axe 0 - Turns all LEDs off

It's running in front of me. What else, what more are you after ?
 

radcom

Member
Thats it, it works exactly as it should, what was I doing wrong. Its such a ludicrously simple program as I thought it should be, thank you, you have just solved something I have been trying to do for months on end and failing each time its amazing I have just had to make small one change to my program to make it work which it now does, its amazing how often you can't see the woods for the trees so thank you all soo much as this is the last bit for my web controlled interface
 
Last edited by a moderator:

MFB

Senior Member
I know you have overcome your problem but for more complex tasks it may be worth remembering that (the free to download) StampPlot Pro plotting/display application also has some quite powerful serial output control features. Including the ability to creat on-screen control panels for use with remote microcontrollers.
 
Top