ambiera home ambiera home

Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name:  Password:    
Ambiera Forum > CopperCube > Programming and Scripting
Javascript interface with RS-232 Serial Port
Author Text

falcon12
Registered User
Quote
2018-10-21 20:15:51

Hi,

I need to make CC communicate with an Arduino card using RS232 serial port.

Any idea ?


niko
Moderator
Quote
2018-10-22 07:05:49

You could use the "system" interface to call another exe which does the communication for you, maybe.


falcon12
Registered User
Quote
2018-10-22 15:32:11

I just saw node.js allow serial port access.


falcon12
Registered User
Quote
2018-10-22 15:32:32

I'm not very used to use Javascript.


falcon12
Registered User
Quote
2018-10-22 15:32:58

If I put this library in the Html page (after or before ?) CC's one


falcon12
Registered User
Quote
2018-10-22 15:33:58

will I be able to call it in Coppercube ?


niko
Moderator
Quote
2018-10-23 09:05:37

Not sure if that will run in the browser, but node probably won't in CopperCube windows .exe target.


falcon12
Registered User
Quote
2018-10-23 23:20:04

You talked about using system interface for launching and exe, ok.

I must make communicate the CC .exe and an Arduino card using RS 232 port in bi-directionnal mode.

I tried to use the .exe to receive data from the card via RS232 port and write these received data on disk in a text file. I use the CC's .exe to read this file every 50 ms. It works ... Strangely I have no access problems ...

But I have such problem in the other direction : From CC to the .exe, using text file too. Sometime the .exe try to reset the text file for reading it while CC is writing in ...

Avoiding simultaneous access promise to be complicated ...


damians
Registered User
Quote
2018-10-24 02:36:23

One way to avoid simultaneous access could be to create another (empty) file called LOCK (or any other name) and then implement the following steps:

for CC
- CC creates the LOCK file;
- CC writes in the shared text file;
- at the end of the writing process, CC deletes the LOCK file;

for the "exe in the middle"
- if the LOCK file exists, the exe can not access the text file and waits until the LOCK file has been deleted;


falcon12
Registered User
Quote
2018-10-24 17:27:32

thanck you. unfortunately CC is not able to do some fileexist or deletefile or renamefile. only read or write


falcon12
Registered User
Quote
2018-10-24 19:02:22

Maybe Niko or someone who's is able to modify CC's source will put these functions in (fileexist, filerename, filedelete).


niko
Moderator
Quote
2018-10-26 08:13:23

Good idea! Will do.


falcon12
Registered User
Quote
2018-10-26 18:00:54

Ok Niko


damians
Registered User
Quote
2018-10-26 23:11:04

Ok, just to give it a try ...

Since CC can send commands to the DOS prompt, I used it as workaround. The downside are the flashes on the screen for opening and closing of the prompt. It's a simple implementation, I hope this can be useful anyway.
I assume that all files are in the same folder of the CC.exe.

--- Write ---

// create the LOCKED file...
system('copy nul .\\LOCKED');

var data = "your data to write in..."

// write the data in the shared file...
ccbWriteFileContent(".\\shared.txt", data);

// delete the LOCKED file...
system('del .\\LOCKED');

// start the exe_in_the_middle, if needed...
system('start .\\your_exe.exe');

--- Read ---

// if the LOCKED file does not exists, create a new file named "rt" (or what you want) and write q into it...
// you can write what you want but to avoid some problem with the string formatting I suggest to write one character only.
system('dir .\\LOCKED || copy nul .\\rt && echo q>>.\\rt');

// read the content of the rt file...
var s = ccbReadFileContent(".\\rt");

// s != undefined when the LOCKED file does not exists.
if (s != undefined && s.charAt(0) == 'q')
{
// read the data from the shared file...
s = ccbReadFileContent(".\\shared.txt");
// delete the rt file...
system('del .\\rt');
print(s); //for debug only...
}

You can download the CC file here: https://drive.google.com/file/d/...


falcon12
Registered User
Quote
2018-10-28 22:04:15

Nice Idea too Damians ! :)

I try using your first idea (semaphore/flags).

The middle .exe receive data from arduino

CC write a file containing data to transmit (f1.txt) and when it has finished it write a file called 'ok'.txt on the disk.

When the middle .exe sees the "ok.txt" file it reads f1.txt and delete ok.txt after. It seems to work.

In the inverse transmission (Arduino to CC) the middle .exe receives data from arduino using RS232, writes it immediately into f2.txt if it has changed. CC read f2.txt every 20 ms and strangely I never had any read error from CC but the problem is not solved.

How CC could be aware, without using a "fileexist" function (CC doesn't allow this), of the existence of a file on the disk ? (I would like to use the same flag/semaphore system like "CC reads a file if it sees ok.txt on the disk).


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "I?ternational" (you are not logged in)


Text:

 

  

Forum Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   





Software: Ambiera Light Forum. © 2008-2018 Nikolaus Gebhardt, Ambiera e.U.