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] SCP accessing variables in RAM getting garbage

Hi,

OOPic III+ Ver C.1.1+ Compiler 6.1.1

I am trying to access RAM memory in SCP and I must be doing something
stupid. If anyone can look over my shoulder and point it out, I would
be very grateful.

The following is the code in my OOPic:

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 following is an excerpt from my C# code:

private void button2_Click(object sender, EventArgs e)

{

serialPort1.Open();

textBox1.Text = "";

response = null;

serialPort1.Write(Cons.node0);

serialPort1.Write(Cons.verifyConnection);

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

SetText(response);

serialPort1.Write(Cons.ackOff);

currentObjName = null;

getMemoryValue("firstByte", 1);

getMemoryValue("secondByte", 1);

getMemoryValue("thirdByte", 1);

getMemoryValue("firstWord", 2);

getMemoryValue("secondWord", 2);

response = null;

serialPort1.Write(Cons.disconnect);

serialPort1.Close();

}

...

private string getMemoryValue(string name, int numBytes)

{

string content;

string retVal = "";

DateTime startTime = DateTime.Now;

int memType = 16; //read/write object's default property

response = null;

errorRet = null;

currentObjName = name;

if (numBytes < 1 || numBytes > 8)

{

throw new Exception("numBytes must be 0<X<9, found: " +
numBytes.ToString());

}

memType += numBytes - 1; // add the number of bytes to read

content = memType.ToString() + Cons.setMemType;

content += getAddr(name) + Cons.setMemAddr;

content += "64" + Cons.setMemSubAddr;

content += Cons.readMemory;

serialPort1.Write(content);

while ((response == null && errorRet == null) || (response != null
&& !response.EndsWith("m") && !response.Contains("*")))

{

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

{

throw new Exception("timed out waiting for a response");

}

}

if (response != null)

{

SetText(name + " - sent: " + content + " received: " +
response);

retVal = response;

}

if (errorRet != null)

{

SetText("Error: " + errorRet);

retVal = errorRet;

}

currentObjName = null;

response = null;

errorRet = null;

return retVal;

}

...

private void SetText(string text)

{

// InvokeRequired required compares the thread ID of the

// calling thread to the thread ID of the creating thread.

// If these threads are different, it returns true.

if (this.textBox1.InvokeRequired)

{

SetTextCallback d = new SetTextCallback(SetText);

this.textBox1.Invoke(d, new object[] { text });

}

else

{

if (textBox1.Text.Length > 0)

{

textBox1.Text += Environment.NewLine;

}

if (text.EndsWith("m"))

{

text = text.Remove(text.Length - 1);

}

textBox1.Text += text;

}

}

Don't be overly concerned with the infrastructure; it works fine
with a similar algorithm for reading default properties of objects. Pay
more attention to the bolded code.

I would expect the output to be the hex values of the initialized values
in the OOPic code. Instead I get garbage. This is the output:

firstByte - sent: 16H105J64LM received: 77

secondByte - sent: 16H106J64LM received: BB

thirdByte - sent: 16H107J64LM received: 40

firstWord - sent: 17H108J64LM received: 116C

secondWord - sent: 17H110J64LM received: 0000

Any help will be appreciated.

Thanks,

Dogulas

[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: