Is it possible in Erlang to use open_port in Windows? - arduino

Background:
I was given a task for college to implement an elevator's source code for an Arduino UNO with a user interface shield that contains: a 7-Segment display and a total of 8 buttons, one for each floor plus two to control the doors. The floor buttons also have an LED.
The hardware is only for human user input, but the brains is made entirely within Erlang. Before we got to implement this project in hardware, we used a simulation that uses wxWidgets to display the following UI: a window that displays the elevator doors, 6 more windows for each floor, and a window for the internal button array of the elevator. This button array is what I'm trying to implement within an Arduino.
Some code:
Our teacher gave us some confusing notes about the use of erlang:open_port/2 that I can't understand yet. The testing code we're using is the following:
-module(proUSB).
-export([start/1, order/2, loop/1, exit/2]).
start(Port_alias) ->
Port = open_port(Port_alias, []),
Pid = spawn(proUSB, loop, [Port]),
port_connect(Port, Pid),
{Port,Pid}.
order(Port,Value) ->
port_command(Port,Value).
loop(P) ->
receive
{P,{data,A}} ->
io:format("Received: ~p~n", [A]),
loop(P);
{'EXIT',P,_Reason} ->
port_close(P),
io:format("Unexpected finalization~n",[]);
exit ->
io:format("Proces finalization~n",[]);
Other -> io:format("Fi ~p~n",[Other])
end.
exit(Pid, Port) ->
port_close(Port),
Pid!exit.
As I've understood and successfully tested in Windows Subsystem for Linux (WSL) with the code mentioned above, all I have to execute in the Erlang shell is
> {Port, Pid} = proUSB:start("/dev/ttyS6").
{#Port<0.7>,<0.82.0>}
This will open the port. I can now send orders to the Arduino USART in the protocol we've designed. To light up the number three in the 7-segment display, we write
> proUSB:order(Port,"D3").
true
Now, if we press the floor button 1, you can see in the terminal
Received: "B1\n"
Received: "\n"
Received: "B1\n"
Received: "\n"
My question:
If I want to use Windows Powershell to do the same connection to the serial port, my teacher told us to write "COM6" instead of "/dev/ttyS6", but as I have tested, I can't get a connection but I get this error
> {Port, Pid} = proUSB:start("COM6").
** exception exit: einval
>
What am I missing? If WSL works with "/dev/ttyS6", why shouldn't it work with Windows when I can use the serial port with "RealTerm: Serial Capture Program"?

Related

Create a bluetooth connection Kivy

This is more of a basic OOP question than a Kivy one. I have an app with 4 buttons. When I press one, I want to initialize a bluetooth connection from my laptop to an arduino uno and also schedule a function that sends bluetooth info every second.
I'm using the following code:
class HomeScreen(Screen):
def OnConnect(self):
print('Start')
port = "COM7"
#connect to bluetooth
bluetooth = serial.Serial(port, 9600)
print("Connected to HC-06")
bluetooth.flushInput()
#schedule a function that sends tester present to arduino
Clock.schedule_interval(self.SendData, 1)
def SendData(self,*args):
bluetooth.write(b"Boop")
Obviously "bluetooth" is not visible outside fct "OnConnect". I want bluetooth to be visible to both OnConnect & SendData but I only want to connect to the arudino when OnConnect is called. Any help is appreciated.
I've looked at the documentation at:
https://kivy.org/doc/stable/api-kivy.clock.html
It says:
If you want to schedule a function to call with default arguments, you can use the functools.partial python module:
So I would think something like this should work:
#schedule a function that sends tester present to arduino
Clock.schedule_interval(partial(self.SendData, bluetooth), 1)
def SendData(self, bt):
bt.write(b"Boop")

BLE write private characteristic to UUID

I use a RN4020 BLE Module to communicate with the VALRT BT Button: https://vsnmobil.com/products/v-alrt/specs
Problem is, I need to send "80BEF5ACFF" within 30sec after connect to the specific private UDID "FFFFFFF5-00F7-4000-B000-000000000000" (see reference: https://github.com/HoyosIntegrity/V.ALRT-bluetooth-spec)
Problem is, I always get "ERR" back from RN4020.
Here is my Initialisation Code (which works):
sf,2 //Factory Reset
+ //echo on
sr,92000000 //configure as Master
r,1 //reboot
F //search devices
X //stop searching
E,0,001EC026C931 //connect to device with mac: 001EC026C931 which is my device
B //Bond
Get a "Connected" back and the Button quit it with a Beep.
Now I tried to Write
CUWV,FFFFFFF5-00F7-4000-B000-000000000000,80BEF5ACFF
with and without "-" but allways get a error back. At github are samples for Android and iOS but its not clear for me what I have to send...
Think I forgotten a prestep, but I dont know which one.
Strange is, when I connect and send "LC" I get this back:
180A
2A23,0012,02
2A24,0014,02
2A25,0016,02
2A26,0018,02
2A27,001A,02
2A28,001C,02
2A29,001E,02
2A2A,0020,02
1803
2A06,0025,0A
1802
2A06,0028,04
1804
2A07,002B,02
2A07,002C,10
180F
2A19,002F,02
2A19,0030,10
FFFFFFA000F74000B000000000000000
FFFFFFA100F74000B000000000000000,0034,0A
FFFFFFA200F74000B000000000000000,0037,02
FFFFFFA300F74000B000000000000000,003A,00
FFFFFFA300F74000B000000000000000,003B,10
FFFFFFA400F74000B000000000000000,003E,00
FFFFFFA400F74000B000000000000000,003F,10
FFFFFFA500F74000B000000000000000,0042,00
FFFFFFA500F74000B000000000000000,0043,10
END
That are some of the services but not all.

Read USB to Serial port Info in Xojo

I am writing a simple code to find the USB to serial port in Windows platform, if the port is what I want (can be filt by VID/PID number), then the program will open the port.
I use MonkeyBread plugin, WinUSBDeviceMBS, with property of VendorID and ProductID, I can select specific USB port. sample code as following.
Dim devices() As WinUSBDeviceMBS = WinUSBDeviceMBS.devices
For Each d As WinUSBDeviceMBS in devices
msgbox d.vendor+"-" + str(Hex(d.VendorID),"0000") + " " +d.product+"-" + str(Hex(d.ProductID),"0000")+d.serialnumber
Next
'this will give you a message box with "FTDI-0403 FT232R USB UART-6001 A60251HV"
Also, with help of Serial.serialport.Name, I can get the COM port name for serial device.
dim i, count as Integer
count = System.SerialPortCount
for i = 0 to count - 1
Msgbox System.SerialPort( i ).Name
next
'this will popup msgbox with "COM1" or "COM3"... all the valid port number, but no vendor info or product info
But I can't find a method to match those two together. Any ideas?
Assuming you are only using Windows you will need to use the registry to get this information.
You can get a list of all COM ports on the system here: HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM. Values will be listed according to their type, so a real serial port will show up with a name \Device\Serialn and data COMxx, other devices might be different. If you look here you can find a name you can use to filter which type of device a COM port belongs to, then simply list these in your application.
You can do this in Xojo by using the Declare statement to hook into the API of the Windows DLLs:
https://docs.xojo.com/index.php/Declare
Here is a document on the Registry API functions, they will be used as described here, but using the Declare statement mentioned above:
http://support.microsoft.com/kb/145679

how to parse customer message?

i use customer message and send it broadcast over radio channel, i use example 6 (CounterSend ) from this link .
when i build this project as micAz on mote 1, after this i use Xsniffer (TOSBase) on the mote that i will use it on the serial usb board (520).
after that i open Xsniffer program to see the radio packet and they appeared as following :
on other hand, to use Xserver i use XMeshBase then type on cygwin terminal :
xserve -device=com4
i got this!! but i can't understand what it received ?
how can i parse the data received ?? and named them as i want ?? ex: i need first byte be the source ??
how to do that ?

Asterisk system ignore some DTMF digits when it called by PABX phone

I am using Asterisk E1 card on CentOS 6.2.
When I call on my asterisk system using a simple pstn or by a mobile phone, the call perfectly run. But when the same number has called by a PABX phone, the asterisk system ignored some digits.
I am using asterisk 1.4 and dahdi 2.4.
I have also tried the dtmfmode = rfc2833 in the sip.conf file. Please some one hemp me resolve this problem.
eg: What actually Our system do, when some one call on our system, we ask for for a 14 digit registration id, and perform some operation on it and it work fine. But when some one call from their own PBX phone (or PABX or soft phone) and enter the registration id, then our system ignore some digits.
I also had this problem some times ago this some PBXs.
this help for me:
relexdtmf=yes
Example of my channel.conf:
; SPAN 1-4 = E1 (1-15,17-31,32-46,48-62,63-77,79-93,94-108,110-124)
; ------------------
switchtype = euroisdn
; Type of Number (TON) for called number
pridialplan = local
; Type of Number (TON) for calling number
prilocaldialplan = private
signalling = pri_cpe
context = incoming
group = 1
immediate = no
overlapdial = yes
channel => 1-15,17-31,32-46,48-62,63-77,79-93,94-108,110-124
; activate this option if there are problems with dtmf detection
relexdtmf=yes
I suppose you meant 'call from PBX internal extension' from 'call from their own PBX phone'.
I have faced issue like this. In my case the issue was with the phone. some old or broken IP phone failed to generate proper DTMF signals. Have you tried different phones like soft phones.

Resources