LED selector
-
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: LED selector
Mark,
I looked at the code in your uploaded project. It does look simple enough to
make a starting point. I have to get around the syntax. I suppose a book on VB
or VS will help.
Any suggestions?
Thanks.
I looked at the code in your uploaded project. It does look simple enough to
make a starting point. I have to get around the syntax. I suppose a book on VB
or VS will help.
Any suggestions?
Thanks.
-
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: LED selector
Dan,
Really? It has only 7 methods and is under 100 lines of code, including white
space, and including the port selection/config dialog. (But not including
IDE-generated files.)
I probably should've commented to indicate the reason I used a timer to read the
port, that reason being, the DataReceived event that the SerialPort object would
raise executes in a separate thread and therefore can't update any UI elements
directly, but would otherwise be fine if all it did was assign variables.
I could port it to C# easily enough, maybe C++ too, that might feel more
familiar. I'll do that when I get back (from Mother's Day dinner.)
You have Visual Studio 2010, right? The binaries were included in the project
too, (in the .\bin\Debug directory) did you try to run it? There's nothing
about it that's specific to the ARMBasic program I included, it just sends
whatever's in the text control over the selected serial port, and dumps whatever
it receives on that port to the other text control.
-Mark
Really? It has only 7 methods and is under 100 lines of code, including white
space, and including the port selection/config dialog. (But not including
IDE-generated files.)
I probably should've commented to indicate the reason I used a timer to read the
port, that reason being, the DataReceived event that the SerialPort object would
raise executes in a separate thread and therefore can't update any UI elements
directly, but would otherwise be fine if all it did was assign variables.
I could port it to C# easily enough, maybe C++ too, that might feel more
familiar. I'll do that when I get back (from Mother's Day dinner.)
You have Visual Studio 2010, right? The binaries were included in the project
too, (in the .\bin\Debug directory) did you try to run it? There's nothing
about it that's specific to the ARMBasic program I included, it just sends
whatever's in the text control over the selected serial port, and dumps whatever
it receives on that port to the other text control.
-Mark
-
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: LED selector
I did run it, but not connected to an ARMmite, because mine is loaded with my C
code program. I understand the program, it's just some of the syntax is strange
to me, like What is 'PortOpenCloseButton.Click'?
I assume that is the button to Open & Close the Serial Port, but where does that
come from? Is that built into VB?
Dan
code program. I understand the program, it's just some of the syntax is strange
to me, like What is 'PortOpenCloseButton.Click'?
I assume that is the button to Open & Close the Serial Port, but where does that
come from? Is that built into VB?
Dan
-
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: LED selector
'PortOpenCloseButton' is the identifier I gave to the top button in the form
'MainForm' (which is designated as the startup form for the app.) .Click refers
to that button's click event, which is raised when the user clicks it.
To create that handler sub routine I double-clicked the button in the form
designer. The behavior of that sub depends on the state of the
_SerialPortObject object/variable, declared at class scope (a form is actually
just a class that inherits System.Windows.Forms.Form.)
If _SerialPortObject.IsOpen is true, it closes it, disables the 'SendButton'
button and changes its own caption to 'Open Port'. If not it creates an object
of type 'CommPortDef', which is another form, the constructor (the New function)
for which accepts a IO.Ports.SerialPort object because I defined it that way (so
the 'CommPortDef' form could initialize its values from the last ones chosen.)
The ShowDialog function opens it modally, blocking its parent form's input until
it is dismissed.
Now here's where it gets quirky: when you pass an object variable to a function,
even though the parameter is declared 'byref', if the object on the caller's
side is 'Nothing' (uninitialized) the callee can't return anything on it. (VB
doesn't support explicit double-indirection, like C/C++ does.) To complicate
matters, the only way to create an IO.Ports.SerialPort object is to call the
static method My.Computer.Ports.OpenSerialPort, which requires valid parameters.
For most object classes I'd make the caller construct it, then pass it, which
would make the line:
_SerialPortObject = f.SerialPortObject
unnecessary. Anyways, that click handler code then re-checks the state of the
_SerialPortObject object (because the user could've closed the CommPortDef form
without selecting a comm port) and if it's open, the handler changes the button
caption to 'Close Port', enables the 'Send' button, and toggles DTR to reset the
ARM board. Lastly it enables the timer object (added to the form as a control
at design time) to read any data recieved on the port every 500 ms (set in the
designer.)
Wow I really didn't do you any favors with this one, did I? More than two words
worth of comments might've been nice!
Oh the file 'ARM Basic Program.bas' is part of the project for editing
convenience only, its compile setting is 'none'.
Sorry about that, it didn't seem quite so convoluted when I was in a hurry.
-Mark
'MainForm' (which is designated as the startup form for the app.) .Click refers
to that button's click event, which is raised when the user clicks it.
To create that handler sub routine I double-clicked the button in the form
designer. The behavior of that sub depends on the state of the
_SerialPortObject object/variable, declared at class scope (a form is actually
just a class that inherits System.Windows.Forms.Form.)
If _SerialPortObject.IsOpen is true, it closes it, disables the 'SendButton'
button and changes its own caption to 'Open Port'. If not it creates an object
of type 'CommPortDef', which is another form, the constructor (the New function)
for which accepts a IO.Ports.SerialPort object because I defined it that way (so
the 'CommPortDef' form could initialize its values from the last ones chosen.)
The ShowDialog function opens it modally, blocking its parent form's input until
it is dismissed.
Now here's where it gets quirky: when you pass an object variable to a function,
even though the parameter is declared 'byref', if the object on the caller's
side is 'Nothing' (uninitialized) the callee can't return anything on it. (VB
doesn't support explicit double-indirection, like C/C++ does.) To complicate
matters, the only way to create an IO.Ports.SerialPort object is to call the
static method My.Computer.Ports.OpenSerialPort, which requires valid parameters.
For most object classes I'd make the caller construct it, then pass it, which
would make the line:
_SerialPortObject = f.SerialPortObject
unnecessary. Anyways, that click handler code then re-checks the state of the
_SerialPortObject object (because the user could've closed the CommPortDef form
without selecting a comm port) and if it's open, the handler changes the button
caption to 'Close Port', enables the 'Send' button, and toggles DTR to reset the
ARM board. Lastly it enables the timer object (added to the form as a control
at design time) to read any data recieved on the port every 500 ms (set in the
designer.)
Wow I really didn't do you any favors with this one, did I? More than two words
worth of comments might've been nice!
Oh the file 'ARM Basic Program.bas' is part of the project for editing
convenience only, its compile setting is 'none'.
Sorry about that, it didn't seem quite so convoluted when I was in a hurry.

-Mark
-
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: LED selector
Dan,
I changed my project to [hopefully] improve its readability:
* Instead of a single button to open/close the port, it now has two buttons, one
to open, one to close (thus avoiding the confusing conditional click handler
logic.)
* SerialPortObject is now a public shared (static) member of MainForm class, to
provide direct access to it from within CommPortDef form/class, thus eliminating
the need for it to be a parameter to CommPortDef's constructor, local member
variable storage for it in CommPortDef class, and of course, any assignments to
or from those.
* I added the gist of what I explained last night, to the code as comments.
* I created an equivilent C# project. (I won't be creating it in C++, C# was
enough of a PITA.)
Now all I need to do is figure out how to replace my upload, if that's possible.
-Mark
I changed my project to [hopefully] improve its readability:
* Instead of a single button to open/close the port, it now has two buttons, one
to open, one to close (thus avoiding the confusing conditional click handler
logic.)
* SerialPortObject is now a public shared (static) member of MainForm class, to
provide direct access to it from within CommPortDef form/class, thus eliminating
the need for it to be a parameter to CommPortDef's constructor, local member
variable storage for it in CommPortDef class, and of course, any assignments to
or from those.
* I added the gist of what I explained last night, to the code as comments.
* I created an equivilent C# project. (I won't be creating it in C++, C# was
enough of a PITA.)
Now all I need to do is figure out how to replace my upload, if that's possible.
-Mark
-
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: LED selector
Mark,
I was looking at the tutorial in VB. They have an example called Picture Framer.
While it's nothing like Serail Port, I can see how it's constructed.
Now I understand, it's like a Chinese Menu(one from column A, one from column
B). I previously thought that you wrote that code in Serial Port. A VB program
consists of snippets of code from the Properties, or Toolbox Menus.
I was looking at the tutorial in VB. They have an example called Picture Framer.
While it's nothing like Serail Port, I can see how it's constructed.
Now I understand, it's like a Chinese Menu(one from column A, one from column
B). I previously thought that you wrote that code in Serial Port. A VB program
consists of snippets of code from the Properties, or Toolbox Menus.
-
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: LED selector
I'm getting up to speed on VB. I have my form setup. I have 6 buttons, Each
sends a different character to the ARMmite board. On receiving a character, the
ARMmite will be programmed to read the A-to-D converter and storing the value in
a 6 x 1 array. Then it will calibrate itself by choosing trip points between
each value in the array. The input voltage to the A-to-D converter will have to
be set to correspond with each button.
I may set it up to echo the character or send an error string. Eventually I'll
have the ARMmite return the A-to-D value, but that requires some data type
conversions, and it's not necessary.
sends a different character to the ARMmite board. On receiving a character, the
ARMmite will be programmed to read the A-to-D converter and storing the value in
a 6 x 1 array. Then it will calibrate itself by choosing trip points between
each value in the array. The input voltage to the A-to-D converter will have to
be set to correspond with each button.
I may set it up to echo the character or send an error string. Eventually I'll
have the ARMmite return the A-to-D value, but that requires some data type
conversions, and it's not necessary.
-
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: LED selector
I need just a little more help.
I have my VB Form setup. It sends a character to the Serial Port(COM4), and
reads an echo.
The ARMmite board reads UART0, and turns on the on-board LED, then it echos back
the received character.
When I use TCLTERM, this works pefectly. The character(p) is echoed, and the LED
lights.
When I use the VB program, the LED does not light, and the returned data is 112.
There should be no returned data if the ARMmite doesn't get the right character.
I can send text messages to the VB Text Box from the ARMmite.
I have the COM4 Port on the PC set to 19200 baud, Odd Parity, and One Stop Bit.
What does TCLTERM use for Serial Comm? I set the Baud Rate to 19200.
I have my VB Form setup. It sends a character to the Serial Port(COM4), and
reads an echo.
The ARMmite board reads UART0, and turns on the on-board LED, then it echos back
the received character.
When I use TCLTERM, this works pefectly. The character(p) is echoed, and the LED
lights.
When I use the VB program, the LED does not light, and the returned data is 112.
There should be no returned data if the ARMmite doesn't get the right character.
I can send text messages to the VB Text Box from the ARMmite.
I have the COM4 Port on the PC set to 19200 baud, Odd Parity, and One Stop Bit.
What does TCLTERM use for Serial Comm? I set the Baud Rate to 19200.
-
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: LED selector
TclTerm does file IO to the serial port, but it also has control over the RESET
and BOOT pins. It overides any settings you make in the Device Manager, usually
19.2Kb 8N1
You may have to do something similar in VB, check the VB project in the files
section Cor_UDP.zip, which does both serial and UDP calls from VB, it was a
diagnostic written here.
and BOOT pins. It overides any settings you make in the Device Manager, usually
19.2Kb 8N1
You may have to do something similar in VB, check the VB project in the files
section Cor_UDP.zip, which does both serial and UDP calls from VB, it was a
diagnostic written here.
-
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: LED selector
I got it fixed. The VB program works the same as TclTerm, except for where I did
things differently. Now I have to work on the Handler in C code on the ARMmite
board.
things differently. Now I have to work on the Handler in C code on the ARMmite
board.