This Forum is Dedicated For all The Object Oriented PIC Lovers .......... The concept behind OOPic is straight forward. Use preprogrammed multitasking Objects from a library of highly optimized Objects to do all the work of interacting with the hardware. Then write small scripts in Basic, C, or Java syntax styles to control the Objects. During operation, the Objects run continuously and simultaneously in the background while the scripts run in the foreground telling the objects what to do.

Friday, February 29, 2008

[oopic] Re: SCP accessing variables in RAM getting garbage

Hi,

OOPic III+ Ver C.1.1+ Compiler 6.1.1

I thought I'd try this again with the dot format that Richard
suggested. I'm supplying a simplified C# code. (Fingers crossed
here)

The OOPic code:

Dim firstByte As Byte

Dim secondByte As Byte

Dim thirdByte As Byte

Dim firstWord As Word

Dim secondWord As Word

Sub Main()

..firstByte = 15 '0F hex

..secondByte = 171 'AB hex

..thirdByte = 205 'CD hex

..firstWord = 4660 '1234 hex

..secondWord = 43981 'ABCD hex

End Sub

The output:

firstByte - sent: 16H105J64LM received: 77m

secondByte - sent: 16H106J64LM received: 33m

thirdByte - sent: 16H107J64LM received: 40m

firstWord - sent: 17H108J64LM received: 116Cm

secondWord - sent: 17H108J64LM received: 116Cm

The C# code:

public partial class Form1 : Form

{

..delegate void SetTextCallback(string text);

..private string currentObjName = null; // prevent race

..private string response = null;

..private string errorRet = null;

..private void Form1_Load(object sender, EventArgs e)

..{

....string content;

....DateTime startTime;

....try

....{

......serialPort1.Open();

......currentObjName = "setup"; // race lock on

......response = null;

......serialPort1.Write(@"\0"); // connect node 0

......serialPort1.Write(@"v"); // verify connection

......// wait for a response

......while (response == null || response.Length == 0) { }

......Console.WriteLine(response);

......serialPort1.Write(@"U"); // acknowlege off

......currentObjName = null; // race lock off

......// Read firstByte

......response = null; // re-init

......content = @"16H"; // memory type read/write RAM

......content += @"105J"; // memory address of firstByte

......content += @"64L"; // sub memory bank 1

......content += @"M"; // read memory

......currentObjName = "firstByte"; // race lock on

......serialPort1.Write(content); // send instructions

......// wait for a response

......startTime = DateTime.Now;

......while ((response == null && errorRet == null)

........|| (response != null

..........&& !response.EndsWith("m")

..........&& !response.Contains("*")))

......{

........if (startTime.AddMilliseconds(1000) < DateTime.Now)

........{

..........throw new Exception("timed out");

........}

......}

......currentObjName = null; // race lock off

......// print response

......if (response != null)

......{

........Console.WriteLine("firstByte - sent: "

..........+ content + " received: " + response);

......}

......// Read secondByte

......response = null; // re-init

......content = @"16H"; // memory type read/write RAM

......content += @"106J"; // memory address of secondByte

......content += @"64L"; // sub memory bank 1

......content += @"M"; // read memory

......currentObjName = "secondByte"; // race lock on

......serialPort1.Write(content); // send instructions

......// wait for a response

......startTime = DateTime.Now;

......while ((response == null && errorRet == null)

........|| (response != null

..........&& !response.EndsWith("m")

..........&& !response.Contains("*")))

......{

........if (startTime.AddMilliseconds(1000) < DateTime.Now)

........{

..........throw new Exception("timed out");

........}

......}

......currentObjName = null; // race lock off

......// print response

......if (response != null)

......{

........Console.WriteLine("secondByte - sent: "

..........+ content + " received: " + response);

......}

......// Read thirdByte

......response = null; // re-init

......content = @"16H"; // memory type read/write RAM

......content += @"107J"; // memory address of thirdByte

......content += @"64L"; // sub memory bank 1

......content += @"M"; // read memory

......currentObjName = "thirdByte"; // race lock on

......serialPort1.Write(content); // send instructions

......// wait for a response

......startTime = DateTime.Now;

......while ((response == null && errorRet == null)

........|| (response != null

..........&& !response.EndsWith("m")

..........&& !response.Contains("*")))

......{

........if (startTime.AddMilliseconds(1000) < DateTime.Now)

........{

..........throw new Exception("timed out");

........}

......}

......currentObjName = null; // race lock off

......// print response

......if (response != null)

......{

........Console.WriteLine("thirdByte - sent: "

..........+ content + " received: " + response);

......}

......// Read firstWord

......response = null; // re-init

......content = @"17H"; // memory type read/write RAM two bytes

......content += @"108J"; // memory address of firstWord

......content += @"64L"; // sub memory bank 1

......content += @"M"; // read memory

......currentObjName = "firstWord"; // race lock on

......serialPort1.Write(content); // send instructions

......// wait for a response

......startTime = DateTime.Now;

......while ((response == null && errorRet == null)

........|| (response != null

..........&& !response.EndsWith("m")

..........&& !response.Contains("*")))

......{

........if (startTime.AddMilliseconds(1000) < DateTime.Now)

........{

..........throw new Exception("timed out");

........}

......}

......currentObjName = null; // race lock off

......// print response

......if (response != null)

......{

........Console.WriteLine("firstWord - sent: "

..........+ content + " received: " + response);

......}

......// Read secondWord

......response = null; // re-init

......content = @"17H"; // memory type read/write RAM two bytes

......content += @"108J"; // memory address of secondWord

......content += @"64L"; // sub memory bank 1

......content += @"M"; // read memory

......currentObjName = "secondWord"; // race lock on

......serialPort1.Write(content); // send instructions

......// wait for a response

......startTime = DateTime.Now;

......while ((response == null && errorRet == null)

........|| (response != null

..........&& !response.EndsWith("m")

..........&& !response.Contains("*")))

......{

........if (startTime.AddMilliseconds(1000) < DateTime.Now)

........{

..........throw new Exception("timed out");

........}

......}

......currentObjName = null; // race lock off

......// print response

......if (response != null)

......{

........Console.WriteLine("secondWord - sent: "

..........+ content + " received: " + response);

......}

......serialPort1.Close();

....}

....catch (Exception ex)

....{

......if (serialPort1.IsOpen)

......{

........serialPort1.Close();

......}

......Debug.WriteLine(ex.ToString());

....}

..}

..private void serialPort1_DataReceived(

....object sender,

....System.IO.Ports.SerialDataReceivedEventArgs e)

..{

....// called on different thread

....if (currentObjName == null)

....{

......throw new Exception("unexpected data");

....}

....response += serialPort1.ReadExisting();

..}

..private void serialPort1_ErrorReceived(

....object sender,

....System.IO.Ports.SerialErrorReceivedEventArgs e)

..{

....// called on different thread

....if (currentObjName == null)

....{

......throw new Exception("unexpected data");

....}

....errorRet += e.ToString();

..}

}

[Non-text portions of this message have been removed]


Yahoo! Groups Links

<*> To visit your group on the web, go to:

http://groups.yahoo.com/group/oopic/

<*> Your email settings:
Individual Email | Traditional

<*> To change settings online go to:

http://groups.yahoo.com/group/oopic/join

(Yahoo! ID required)

<*> To change settings via email:
mailto:oopic-digest@yahoogroups.com
mailto:oopic-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
oopic-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:

http://docs.yahoo.com/info/terms/

No comments: