AXE027 for Serial Communication

woody79

New Member
The title pretty much says it all. I want to use the AXE027 which is the USB to jack cable to read eg.
Code:
debug b0
into a basic C#:)D), C++:)D) or VB:)p). Is this possible?
 

marcos.placona

Senior Member
Totally possible, just read about serin and serout / sertxd

If you go to the finished projects, there's some examples posted by Dippy in VB. Anything else you may need, just let us know and we shall help you with some code examples
 

hippy

Technical Support
Staff member
A forum search will show up discussion on using various programming languages to do this ( and I'm sure there'll be another list of what people use and prefer arriving here shortly ) plus example code.

From the PC's perspective, handling the data is no different whether it comes via USB and a Virtual Serial Port or a physical Serial Port.

If you've done serial comms in your preferred language before then you should have no problems. If not, that's what to read up on and get to grips with; the PICAXE side is the easy part.

If you need to understand how to use the PC programming language you've chosen then you'll probably be better off consulting in forums dedicated to those than here.
 

Technical

Technical Support
Staff member
Just use Device Manager to find out which com port is allocated to your AXE027 and then use that within the programming language as if it was a normal serial port.

The only real issue is if you have a com port number greater than 9, then due to the Windows operating system CreateFile API operation you will need to use "\\\\.\\COM10" rather than "COM10" as the port name.
 

woody79

New Member
This just hangs the program on the computer...
Code:
private void readbtn_Click(object sender, EventArgs e)
{
	if (sp.IsOpen)
	{
		try
		{
			readdatatxt.Text = "Reading...";
			readdatatxt.Text = sp.ReadLine();
		}
		catch (Exception x)
		{
			readdatatxt.Text = "";
			MessageBox.Show(String.Format("Could not read data from {0}.\r\nReason: {1}", sp.PortName, x.Message));
		}
	}
	else
	{
		MessageBox.Show("Open the serial port first","Port not Open",MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
	}
}
Any reason why?
 

hippy

Technical Support
Staff member
Had to polish the crystal ball there but to cut a long story short, if that is where the code is hanging ( does it print "Reading...", you don't say ), that it doesn't give any erorr message means it can only be stuck in sp.ReadLine().

In which case the PC doesn't see any received data with correct line termination. There could be a number of reasons for that -

Wrong serial port opened
Serial port not enabled
Wrong baud rate set
Wrong handshaking / flow control options set
No data sent from the PICAXE
Data not sent to correct output pin / Serial Out
Data from PICAXE doesn't have correct line terminator
Connected to wrong serial port
 

moxhamj

New Member
Agree hippy. Too many questions. That working instructable link from post 6 actually is several days of fixing things that didn't work. I'd suggest getting something working first by copying a design, then you can try simplifying it. vb.net and c.net are almost the same language - leave out the { and } and it becomes vb.net. And there is a lot more to the code than what you have above. How many bytes are you reading in, for instance, and what is the timeout delay?
 

woody79

New Member
completely agree with you both, was doing something else at the same time.
@Dr_Acula: From what I can remember about vb.net (haven't touched it in 2-3 years) Dim count As Integer is not the same as int count;

I use the serial port that the picaxe programming editor uses to send the program.
If I leave the PPE debug window open when i try to read data it returns access denied.
Don't know what port or baud rate should be used when using serout.
Code:
main:
	readadc 4,b0
	debug b0
	pause 1000
	goto main
 

hippy

Technical Support
Staff member
First thing is always to open HyperTerm, Terminal, a Terminal Emulator or use the PICAXE Programming Editor Terminal function to check there's something coming back from the PICAXE.

I'd recommend starting with the Programming Editor Terminal as that forces default handshaking so should show something if any data at all is coming back. Then of course I'd recommend my own Terminal Emulator ...

http://www.picaxeforum.co.uk/showthread.php?t=8961

HyperTerm is harder to configure and get working so not the best place to start if not sure of what's going on. The other choices prove something does work or doesn't so they avoid wasting ages trying to get get something to work which never will.
 

hippy

Technical Support
Staff member
@Dr_Acula: From what I can remember about vb.net (haven't touched it in 2-3 years) Dim count As Integer is not the same as int count;
I thought they were the same with VB.Net and C#.Net but different (32-bit) to VB6's Integer (16-bit) same as VB6's Long (32-bit). In most cases it shouldn't matter.

Code:
main:
	readadc 4,b0
	debug b0
	pause 1000
	goto main
There's your problem - DEBUG.

DEBUG doesn't send back data in a form which can be read as text. Using a Terminal display will show that; just a long stream of 'gibberish'.

What you need to do is use SERTXD(#b0,CR,LF) and that should work. Baud rate will be 4800 at 4MHz.
 

moxhamj

New Member
Dim Count as integer LOL. You would have to pick my favourite variable name! (It is the Count here...)

You are getting "access denied" because only one program can access the serial port. So if you use debug, the download program still has the serial port open. I'm pretty sure the picaxe editor closes the serial port if you don't use a debug though.

The instructable takes you through the steps on this, but essentially you need to download your program, with no debugs etc, get out of the picaxe editor and get into vb.net or c.net. The error message in .net at least says that another program still has control of the serial port.

Re the baud rate - it doesn't matter except that it needs to be the same on the picaxe and on the .net program. Step 4 and Step 6 of the instructable - I chose 2400 because it is the fastest a picaxe will go without the complexities of overclocking.
 
Last edited:
Top