Serial Simulation

Post Reply
alanwms
Posts: 95
http://meble-kuchenne.info.pl
Joined: Fri Dec 04, 2020 2:29 pm
Has thanked: 23 times
Been thanked: 3 times

Serial Simulation

Post by alanwms »

I have success with my serial RS232 comms, but don't seem to be able to inject data at simulation time.

How much stuff do I have to go through in order to allow me to inject a serial string?

I did search around, but came up empty. Used to be easy in FC7 era.

medelec35
Matrix Staff
Posts: 692
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 242 times
Been thanked: 244 times

Re: Serial Simulation

Post by medelec35 »

Hi
Injectors have been removed with V9, so now you don't have to add additional injector components to receive data.
Here are my properties to receive injected data:
I used the attached flowchart to send the data to the target device then the send part was disabled.
Attachments
UART Injector Test.fcfx
(11.98 KiB) Downloaded 20 times
Injector Test.png
Injector Test.png (365.23 KiB) Viewed 525 times
Martin

alanwms
Posts: 95
Joined: Fri Dec 04, 2020 2:29 pm
Has thanked: 23 times
Been thanked: 3 times

Re: Serial Simulation

Post by alanwms »

I want to type in a string "B11021000" from my keyboard while in simulation and have the simulator accept it as a receive function.

mnfisher
Valued Contributor
Posts: 399
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 49 times
Been thanked: 227 times

Re: Serial Simulation

Post by mnfisher »

One way to do this (and I'm sure there must be an easier one....) is to use a virtual com port.

For example - I used the free trial from https://www.eltima.com/virtual-com-port-windows-10/
Then I create a pair of com ports (I had 13 -> 14) and connect FC Data source com port to 14... (it takes some time for the ports to show up if FC is running whilst they are created)
Then open 'putty' (or your favourite terminal program) on COM13 Then you can type whatever to the simulation com port (note that this step isn't required if the receive program is running on an MCU - as you can connect directly using 'putty')

The problem here is that the eltima software is expensive (there is a 14 day free trial). There are other virtual serial port programs available (some free) - though I haven't tried them.

Note that the 'logic' of the sample above means that the string received must be received in 10ms (so type fast) - or change the timeout on the ReceiveString function - or receive the data to a buffer and look for a 'termination' character (newline or no. characters received etc)

Martin

mnfisher
Valued Contributor
Posts: 399
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 49 times
Been thanked: 227 times

Re: Serial Simulation

Post by mnfisher »

I feel it should be possible to use the COM / File injector API components (under API) though my small trial didn't work with either....

Martin

medelec35
Matrix Staff
Posts: 692
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 242 times
Been thanked: 244 times

Re: Serial Simulation

Post by medelec35 »

With the attached Flowchart, you can type into the Human Interface RX Queue of the Console, while the simulation is running.
The LCD will show the chars as you are typing.
Attachments
UART Injector Test2.fcfx
(12.94 KiB) Downloaded 17 times
Martin

chipfryer27
Valued Contributor
Posts: 102
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 84 times
Been thanked: 47 times

Re: Serial Simulation

Post by chipfryer27 »

Hi Martin

If I'm not mistaken I think they're referring to FC not being able to simulate a Receive Interrupt.

Having used this interrupt many times to populate the CB I'm quite familiar with it and know it works (at least in my applications). In simulation, if an Injector could directly populate the CB then that would negate any need for an Interrupt to do so and would maybe be quite an easy component / feature to include?

Whilst learning about the CB I used to include a push button that was polled in the main loop. If pressed (simulating my interrupt) it would branch and populate the CB with whatever test string I chose. The main loop (which polled the CB) would then react. My test string(s) would include junk messages and of course the proper one(s) too thereby ensuring correct "polling" of the CB.

Regards

medelec35
Matrix Staff
Posts: 692
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 242 times
Been thanked: 244 times

Re: Serial Simulation

Post by medelec35 »

Hi
The Flowchart I posted was only to work with simulation, not hardware.
I just wanted to establish if entering data on the console was what Alan was after.
If it was then I would then create a flowchart that works in simulation and hardware.
It would use an RX interrupt, circular buffer & LCD control.
For example, send

Code: Select all

#
and the LCD is cleared.
Send

Code: Select all

;
and the chars are printed on the next row of the LCD.

I have now decided the flowchart would come in handy as it works with both simulation and hardware, So I have uploaded it.
The secret is to use IsSim component to enable a timer interrupt within simulation only.
The timer interrupt will call the RX interrupt macro.
It's important the timer interrupt does not call the RX interrupt macro on hardware.
In simulation mode the characters are entered within the Human Interface RX Queue of the Console
What I have noticed is you need to click on the blank area of the Human Interface RX Queue once, enter the char and then click on the blank area for the second time.
You then should be good to keep typing chars from your keyboard.
As soon as you type a char, it will disappear as it is being received within the CB via RX ISR user macro.
Attachments
UART Injec Test With CB.fcfx
(20.08 KiB) Downloaded 24 times
Martin

Post Reply