PC Win 8/ 8.1 app writing - I've got out of touch.

Dippy

Moderator
After a period of time as hardware-only engineer I can get back to PICAXE.
I'm trying to write some simple PC software to talk to PICAXE via serial cable.

I now realise I've got a bit out of touch.

In the olden days I could knock up crude VB6 serial in a coffee-break.
A few years later I managed to use Vstudio 2008 - phew, it took ages to do something simple.
Now I try the same same thing in the latest Studio. Very powerful but it's driving me nuts.
(As in Excel, super-clever, but I only use 1% of it's capability. And, as usual, if I had time/patience I would find it better).


Then I tried XOJO 2014 ( silly name for RealBASIC). Back to simple. But is it any good.
I tried a couple of other offerings but wasn't taken.

Does anyone have opinions?
Here's my wishlist.
1. Must be compatible with Win8 / 8.1.
2. Produce a distributable install or exe file.
3. Ideally cross-platform on to Mac.
4. BASIC or C/C++ don't mind.
5. Easy to write as I have become rusty.
6. No need for Mobile Apps.
7. No requirements to download or update any new system files or Java.
8. I don't want Little Johnny's compiler which doesn't have any support (or future).
9. I'll need Manufacturer/Author's support. i.e. not 'Forum only'.

My parameter list doesn't include 'Free'. i.e. I'll pay if it does what I need.

I guess many people here have searched & tried all sorts. Suggestions?
Thanks all.
 

grim_reaper

Senior Member
I 'live' inside Visual Studio (2013) and communicate with all my PICAXE projects via serial (well, technically it's serial over ethernet, which avoids the whole serial port thing at the PC end because I can just open a TCP connection). I realise that doesn't help with item #3 on your list.

However, if you need any VS specific help, please let me know.
 

Dippy

Moderator
Thanks GR. Well, cross-platform is the WIBNI but I wouldn't lose too much sleep if it were Windows only.

Does the Freebie VS allow calls to Serial port? I am struggling with on-line (so-called) Help.
 

grim_reaper

Senior Member
There are supposedly all sorts of problems with the built-in .NET SerialPort routines; but most Google searches only seem to mention Framework v2.0 and 3.5. I had one issue with closing and re-opening a port a few years ago, and that's quite easily solved by closing it in a different thread. Codes been running on my server at home ever since, so I consider it fixed.

And having just read the page at the end of Technical's link in #4, that covers everything I can think of! Must've been the same page I read years ago.
One for the favourites list.
 

Hendriks

Member
VB6 was maybe the last of the line 'rapid application development' tools.
VB.NET isn't rapid anymore and in fact it is also not BASIC anymore (as in Beginners).
I have been a basic fan from ZX81 up to VB6 but VB.NET is something different.

Luckely you may still use your VB6 serial control (mscomm) in VB.NET:
http://support.microsoft.com/kb/823179
 

Jamster

Senior Member
[Bits of] .NET's now open source and Microsoft have said they're making ports of the virtual machine for Mac so it seems to be your best option still :p

Could always join me in learning Erlang :p
 

Dippy

Moderator
Thanks for the suggestions and tips gents.

It reminds me of Excel i.e. really sophisticated and all singing.
But I only use 1% of it's capabilities.

I don't need anything so pretty, I just need to get some 'Noddy' programmes up and running.
I haven't got enough hair left to risk tearing it out and I don't have the spare time anymore.

In XOJO (aka RealBASIC) I had crude serial up and running in a couple of hours from scratch.
Not pretty and it wouldn't impress the neighbours I'll admit.
And obviously no comparison in terms of features compared to VS.

I could have done the same in old VB6 so I appreciate what you are saying Hendriks.

Thanks jamster but I need something to work by the end of coffee-break :)


PS. Is there soemthing wrong with Forum?
So Slow.
On my W8.1 PC Firefox is still waiting, IE11 is taking in excess of 2 minutes to get the pages.
And my old PC with XP + IE8 is taking 3 minutes to refresh.
Both old and new PCs timed-out trying to log-in.

Then I tried Firefox again and it was almost instant.
All other sites are very quick in either browser.
 

inglewoodpete

Senior Member
PS. Is there soemthing wrong with Forum?
So Slow.
On my W8.1 PC Firefox is still waiting, IE11 is taking in excess of 2 minutes to get the pages.
And my old PC with XP + IE8 is taking 3 minutes to refresh.
Both old and new PCs timed-out trying to log-in.

Then I tried Firefox again and it was almost instant.
All other sites are very quick in either browser.
Having the same problems in OZ. I thought it was to do with a severed undersea cable (one cable Singapore to Australia is cut) but if you're having problems in the UK, then maybe it's a server problem.
 

Circuit

Senior Member
PS. Is there soemthing wrong with Forum?
So Slow.
On my W8.1 PC Firefox is still waiting, IE11 is taking in excess of 2 minutes to get the pages.
And my old PC with XP + IE8 is taking 3 minutes to refresh.
Both old and new PCs timed-out trying to log-in.

Then I tried Firefox again and it was almost instant.
All other sites are very quick in either browser.
Possibly this problem again; from Technical http://www.picaxeforum.co.uk/showthread.php?26689-Forum-performance-issues&p=273909&viewfull=1#post273909

"The software and website are fine. Unfortunately, like almost all popular web forums, we are getting more and more attacks from China based spamming servers onto the new registration page, often several thousand requests a minute.
None of these fake registration attempts get through due to our deliberately tough registration process, but they just slow down system response at times.

We ban known IP addresses as we can, but new ones just pop up a few days later. We are actively looking at other methods to try and resolve this. "
 

nekomatic

Member
Ooh, that new VS edition is interesting, but Android and iOS are not Mac...

So would it be mischievous of me to suggest (a) Python/Qt or (b) LabVIEW? ;-)
 

grim_reaper

Senior Member
Python seems to be good for new learners - I'm helping my 8 year old learn it. Yet to get to serial port stuff though.
 

Dippy

Moderator
Interesting, neckomatic.

How much does Labview cost?
I've used it in the past but never checked how much it would set me back.

Python. I've never used it.
Can it produce a distributable app that doesn't require any fiddling around on target PC? (Other than installing the actual application - that is what I meant).
 

Dippy

Moderator
Thanks hippy.
That's no good then. I've just seen the price of Labview so that's off the Menu too.
It has to produce standalone code/app with no additional downloads/installation/modules/java or any nerd-time whatsoever :).
Thanks anyway.
 

Dippy

Moderator
I just downloaded it Tom.
An interesting option - a sort of halfway-house between line-by-line and VB style.
 

moxhamj

New Member
I have tried many programs but keep going back to visual studio. This sort of code has been working for many years and seems to work in all the versions of visual studio for the last 7 years at least.

1) At the top of the program, add
Imports System.IO ' for serial ports
Imports System.Windows.Forms ' for extra forms control
Imports Strings = Microsoft.VisualBasic ' so can use things like left( and right( for strings

2) In the toolbox in components there should be SerialPort. Drop one on the form. SerialPort1
3) Drop in a timer - Timer1 and set it to 100ms

4) in the form startup,
Public Class Form1
Dim InPacket(0 To 2000) As Byte ' buffer for packets coming in
Dim OutPacket(0 To 2000) As Byte ' buffer for packets going out

5) When the program starts, turn on the timer and open the com port (you can do this with a button too if you want)
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True ' turn on timer
OpenComPort() ' open the com port
End Sub

6) Add the code to open the com port with all the correct parameters

Sub OpenComPort()
Try
SerialPort1.PortName = "COM1"
SerialPort1.BaudRate = "9600"
SerialPort1.Parity = IO.Ports.Parity.None ' no parity
SerialPort1.DataBits = 8 ' 8 bits
SerialPort1.StopBits = IO.Ports.StopBits.One ' one stop bit
SerialPort1.Open() ' open the port
SerialPort1.DiscardInBuffer() ' clear the input buffer
'SerialPort1.Handshake = System.IO.Ports.Handshake.RequestToSend 'handshaking on (or .None to turn off)
Catch ex As Exception
MsgBox("Error opening serial port - is another program using the selected COM port?")
End Try
End Sub

I left handshaking as a comment - enable this if you want hardware handshaking

7) Sending a byte

Sub SendByte(ByVal c As Byte)
OutPacket(0) = c ' send as a byte through an array
If SerialPort1.IsOpen = True Then
SerialPort1.Write(OutPacket, 0, 1)
End If
End Sub

and if you like, you can bundle up lots of bytes in the OutPacket array and send them as a group.

Reading bytes - this is a bit more complex and I tried a few things before I found a solution that works. Essentially, set the timer so it runs every 100ms and grab bytes and add them until there are none left. I found this more reliable than trying to trigger an event when a byte came in.

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False ' so don't get stuck in a loop reading bytes
CollectBytes() ' fetch bytes frequently
Timer1.Enabled = True
End Sub

And now process the bytes

Private Sub CollectBytes()
Dim BytesToRead As Integer
Dim i As Integer
If SerialPort1.IsOpen = True Then
Do
If SerialPort1.BytesToRead = 0 Then Exit Do ' no more bytes
BytesToRead = SerialPort1.BytesToRead
If BytesToRead > 2000 Then BytesToRead = 2000
SerialPort1.Read(InPacket, 0, BytesToRead) ' read in a packet
For i = 1 To BytesToRead
ReceivePacket(InPacket(i - 1)) ' send to the packet processing routine
Next
Loop
End If
End Sub
 

inglewoodpete

Senior Member
The doc's code is more-or-less what I use when communicating with a PICAXE.

With a PICAXE or microcontrollers in general, there may be times when you want to transfer all byte values as single byte values Ie 0-255. Computers seem to want to interpret some byte values as part of a multi-byte character or expression.

To treat incoming bytes as byte values, add the following line to Sub OpenComPort():
SerialPort1.Encoding = System.Text.Encoding.GetEncoding(28591)

Edit: Just noticed, this was mentioned by Technical in post #4
 

moxhamj

New Member
Ah, good point inglewoodpete. The byte problem is one of those bugs that takes a while to find. The code I posted it was a hack I found that worked - essentially send all data through two byte arrays, which changes the data definitely into bytes. Your solution should work too.
 

DStewert

New Member
Consider Robot Basic

It is a free interpreted basic that can create stand alone .exe and is very easy to implement serial comms , TCP/IP, UDP. I have a picaxe controller which communicate serial to a PC and from there I use RB to relay data to my main PC using UDP.
For Windows Xp thru 8.1. No mac unfortunately.
 

nekomatic

Member
You can build standalone Python apps, that don't need a Python installation, using py2exe on Windows or py2app on Mac. I'm not sure whether you need to use an installer for Qt or if it can also be bundled into the exe or app (other GUI frameworks are available too, of course) but I use apps that I know are built on Qt and I've never had to download or install it separately so at worst it must be possible to incorporate it into a standard Windows or Mac installer.

I'm a huge fan of LabVIEW but I knew I was being mischievous suggesting it in this case - but for reference, the minimum cost to be able to build standalone apps on Windows is a shade over £2k, for the Base Package plus Application Builder. You would need to install the LabVIEW runtime and VISA serial support along with your built app but the application builder can create an installer that does all that. For Mac unfortunately there's no base package so you're looking at a further £3700 or so. You'll never look back if you do though :)
 

Dippy

Moderator
I've used Labview a bit, it's vey clever like all NI stuff, but it's an expensive no-goer at this point.

Thanks for the VB snippets Drac and IP.
I'm really struggling with VS Express 2013. I'm being very thick.

It looks very comprehensive but I'm getting nowhere - I think I need someone over my shoulder for an hour to kick-start my cerebellum.

nekomatic, have you tried producing a Python standalone app and installing it on a virgin PC+O/S?
That's the sort of 'standalone' I would need. No extra nerdification.
It must simply pop-in sans faff ;)

DStewart, thanks for RB. It looks a little like Liberty Basic and is easy to drive.
And an exe compiled on Win8 certainly worked on an old XP machine.
 

inglewoodpete

Senior Member
Thanks for the VB snippets Drac and IP.
I'm really struggling with VS Express 2013.
VS is not simple like so many of the earlier VBs up to VB6. With the introduction of .Net and MS's alignment of VB with VC, came a different mindset. I ended up doing a couple of (evening class) modules from a programming diploma/certificate course at a nearby technical college.

For me it was about understanding objects and classes. Once that was in hand then it all made more sense.

I'm being very thick.
Probably not but we can take a vote if you like:).
 

nekomatic

Member
I confess that I haven't tried creating standalone apps from Python myself, though it would be a good learning exercise for me to give it a shot. I had a quick google bing and it looks as if PyQtDeploy is the tool you'd want to use, if you were using Qt for the GUI - alternatively it might be easier to check out Portable Python for Windows (edited to add: using Tkinter or WxPython for GUI). I expect there should be an equivalent for Mac and Linux out there, and of course there will already be a native Python installation on Macs and Linux machines although what version you get will vary. There are quite a lot of questions and answers on stackoverflow around this subject if you need more info.

On which side are you trying to avoid nerdification though - yours, or the user's? Does it matter how many libraries etc need to get installed as long as the user only has to see a one-click install file?
 

moxhamj

New Member
I'm really struggling with VS Express 2013.
Yes, +1 to grimreaper. Which bit? If we have to resort to screenshots, that is cool. Just recently VS drove me a bit mad because several of the critical toolboxes decided to "undock" and then wanted to "redock" in a different way that tripled the number of mouse clicks doing simple things.

I still keep coming back to VS though. Drop some controls on a form, double click them, add in code.

Maybe start super simple. Take a D9 female socket, solder pins 2 and 3 together, and send out a byte and then get it back again. Getting that working is a long way towards getting a full serial comms system talking to a picaxe.
 

Dippy

Moderator
Well, there's problem Number ONE.

Even on downloaded sample projects I cannot find the Form display or how to add a control.
VB6 was a piece of cake and I've done piles of progs in that.
And, yes, I have done loads of comms stuff in VB6.
But this thing..

There is not a mention of Forms or Controls on any dropdown I can see.
I can find the code etc. in the Object Browser, but nothing to do with creating/viewing Forms & Controls.

Hang on I've accidentally created a form, but it's not called a form.
How do I add controls... where are they hidden ... time for a cuppa.
Oh Lor I give in :)

In the time I have faffed around here I could have a done a complete Logger data extraction app in XOJO ;)
 

Technical

Technical Support
Staff member
In those examples use View menu>Solution Explorer.
Then just double click on whatever form/module you want to edit in the Solution Explorer list.
 

grim_reaper

Senior Member
Yes, the Solution Explorer is usually the base list of stuff you want.

Just right click on any item to see the things you can do with it - View Code or View Designer should be things you're after.

Stay away from the Object Browser unless you're looking for something; it's more like a road map (of the entire library set you've got loaded) and will only give you basic "read only" information.

Once you've got the Solution Explorer visible, if the Properties window isn't showing, press F4 to get at it. Then you should be in pretty much the same situation as a standard VB6 layout (with a lot of annoying fiddling with toolbars and window edges to get it comfortable!)

Another tip; once you're happy, use Tools --> Import/Export Options to export everything to a safe place, then when you inevitably accident move a toolbar or window and it vanishes, just re-import your settings!
 
Top