Is it possible to send lin frame from CANoe without using the LDF file - can-bus

I'm new to CANoe and CAPL, currently using Vector CANoe 16 SP2 Demo version. I'm able to send a 8 bytes of CAN message as shown below with the help of CAPL script without CAN database file.
/*#!Encoding:1252*/
includes
{
}
variables
{
message 0x01 msg1;
msTimer tm;
}
on start
{
setTimer(tm,10);
}
on timer tm
{
Send_msg_1();
setTimer(tm,10);
}
void Send_msg_1()
{
int i;
msg1.msgChannel=1;
msg1.dlc=8;
for(i=0;i<8;i++)
{
msg1.byte(i)=0x1;
}
output(msg1);
}
enter image description here
Now, I want to send 8 bytes of lin frame with CAPL without the LDF file. I've written the following code for it
/*#!Encoding:1252*/
includes
{
}
variables
{
linFrame 0x01 msg1;
msTimer tm;
}
on start
{
setTimer(tm,10);
}
on timer tm
{
msg1();
setTimer(tm,10);
}
void msg1()
{
int i;
msg1.msgChannel=1;
msg1.dlc=8;
for(i=0;i<8;i++)
{
msg1.byte(i)=0x1;
}
msg1.rtr=0;
output(msg1);
msg1.rtr=1;
output(msg1);
write("Frame Transmitted");
}
But, I'm not sure if its getting really transmitted because it is showing like this in trace window
enter image description here
If its not correct. Please let me know the correct way of transmitting a lin frame in CANoe with CAPL scripting.
Thanks in advance :)

Related

Arduino Temboo Google Sheets response code 0 returned, still not working

So I'm trying to update a gooogle sheet through Temboo and an Arduino Yun. I can run the AppendValues choreo and AppendRow choreo from the Temboo site just fine and everything updates, but running the choreos through the arduino .ino shows no updates on the google sheet. I get a return code of 0 from running the choreo though. So I know Oauth is working and google and temboo are talking, so there must be a problem in my code?
I have double checked AccountName, Password, AppKey, refresh token, client secret, client id, spreadsheet id, spreadsheet name, etc in the Arduino code (tried AppendValuesChoreo and AppendRowChoreo).
AppendRow .ino:
// Include required libraries
#include <Bridge.h>
#include <Temboo.h>
// Debug mode ?
boolean debug_mode = true;
void setup() {
//start serial
Serial.begin(115200);
delay(4000);
while(!Serial);
// Start bridge
Bridge.begin();
Serial.println("Setup complete. Waiting for sensor input...\n");
}
void loop() {
Serial.println("\nCalling the /Library/Google/Spreadsheets/AppendRow Choreo...");
// Append data to Google Docs sheet
runAppendRow();
// Repeat every 10 seconds
delay(10000);
}
// Function to add data to Google Docs
void runAppendRow() {
TembooChoreo AppendRowChoreo;
// Invoke the Temboo client
AppendRowChoreo.begin();
// Set Temboo account credentials
AppendRowChoreo.setAccountName("");
AppendRowChoreo.setAppKeyName("myFirstApp");
AppendRowChoreo.setAppKey("");
// Identify the Choreo to run
AppendRowChoreo.setChoreo("/Library/Google/Spreadsheets/AppendRow");
// your Google username (usually your email address)
AppendRowChoreo.addInput("Username", "");
// your Google account password
AppendRowChoreo.addInput("Password", "");
// the title of the spreadsheet you want to append to
AppendRowChoreo.addInput("SpreadsheetTitle", "Yun");
// Format data
String data = "123,921";
// Set Choreo inputs
AppendRowChoreo.addInput("RowData", data);
// Run the Choreo
unsigned int returnCode = AppendRowChoreo.run();
// A return code of zero means everything worked
if (returnCode == 0) {
if (debug_mode == true){
Serial.println("Completed execution of the /Library/Google/Spreadsheets/AppendRow Choreo.\n");
Serial.println("Row added: " + data);
}
} else {
// A non-zero return code means there was an error
// Read and print the error message
while (AppendRowChoreo.available()) {
char c = AppendRowChoreo.read();
if (debug_mode == true){ Serial.print(c); }
}
if (debug_mode == true){ Serial.println(); }
}
AppendRowChoreo.close();
}
AppendVValues .ino:
#include <Bridge.h>
#include <Temboo.h>
int calls = 1; // Execution count, so this doesn't run forever
int maxCalls = 10; // Maximum number of times the Choreo should be executed
void setup() {
Serial.begin(9600);
// For debugging, wait until the serial console is connected
delay(4000);
while(!Serial);
Bridge.begin();
}
void loop() {
if (calls <= maxCalls) {
Serial.println("Running AppendValues - Run #" + String(calls++));
TembooChoreo AppendValuesChoreo;
// Invoke the Temboo client
AppendValuesChoreo.begin();
// Set Temboo account credentials
AppendValuesChoreo.setAccountName("");
AppendValuesChoreo.setAppKeyName("");
AppendValuesChoreo.setAppKey("");
// Set Choreo inputs
AppendValuesChoreo.addInput("RefreshToken", "");
AppendValuesChoreo.addInput("ClientSecret", "");
AppendValuesChoreo.addInput("Values", "[[15,49]]");
AppendValuesChoreo.addInput("ClientID", "");
AppendValuesChoreo.addInput("SpreadsheetID", "");
// Identify the Choreo to run
AppendValuesChoreo.setChoreo("/Library/Google/Sheets/AppendValues");
// Run the Choreo; when results are available, print them to serial
AppendValuesChoreo.run();
while(AppendValuesChoreo.available()) {
char c = AppendValuesChoreo.read();
Serial.print(c);
}
AppendValuesChoreo.close();
}
Serial.println("Waiting...");
delay(30000); // wait 30 seconds between AppendValues calls
}
Looks like they only support rev1, and the original shields. Hopefully they'll update services for the rev2 boards soon.

PIC32MZ2048ECH144 USART- Junk characters transmitted

I am new to MPLAB X Harmony framework and also in working with microcontrollers. I am working on PIC32MZ2048ECH144. I wanted to transmit a simple string using USART and see it displayed in RealTerm terminal.(I have tried HyperTerminal also.) Whatever string I send, I see only junk characters being displayed. When I browsed for the solution for this problem of junk characters being displayed, there were suggestions to check for the baud rate. I have set the baud rate to be 9600 in MPLab Harmony Configurator(Options -> Harmony Framework configuration -> Drivers -> USART -> USART Driver Instance 0 -> Baud Rate -> 9600). So I used the following line in app.c to explicitly set the baud rate.(PBCLK is 100MHz). But no luck!
PLIB_USART_BaudRateSet(USART_ID_2, 100000000 ,9600);
The code for app.c file:
/*******************************************************************************
Start of File
*/
const char *string1 = "*** UART Interrupt-driven Application Example ***\r\n";
const char *string2 = "*** Type some characters and observe the LED turn ON ***\r\n";
APP_DATA appData =
{
};
APP_DRV_OBJECTS appDrvObject;
void APP_Initialize ( void )
{
appData.state = USART_ENABLE;
appData.InterruptFlag = false;
}
bool WriteString(void)
{
if(*appData.stringPointer == '\0')
{
return true;
}
while (PLIB_USART_TransmitterIsEmpty(USART_ID_1))
{
PLIB_USART_TransmitterByteSend(USART_ID_1, *appData.stringPointer);
appData.stringPointer++;
if(*appData.stringPointer == '\0')
{
return true;
}
}
return false;
}
bool PutCharacter(const char character)
{
if(PLIB_USART_TransmitterIsEmpty(USART_ID_1))
{
PLIB_USART_TransmitterByteSend(USART_ID_1, character);
return true;
}
else
return false;
}
void APP_Tasks ( void )
{
/* check the application state*/
switch ( appData.state )
{
case USART_ENABLE:
/* Enable the UART module*/
PLIB_USART_BaudRateSet(USART_ID_1, 100000000 ,9600);
PLIB_USART_Enable(USART_ID_1);
appData.stringPointer = string1;
appData.state = USART_TRANSMIT_FIRST_STRING;
break;
case USART_TRANSMIT_FIRST_STRING:
if(true == WriteString())
{
appData.state = USART_TRANSMIT_SECOND_STRING;
appData.stringPointer = string2;
}
break;
case USART_TRANSMIT_SECOND_STRING:
if(true == WriteString())
{
appData.state = USART_RECEIVE_DONE;
}
break;
case USART_RECEIVE_DONE:
if (appData.InterruptFlag)
{
if(true == PutCharacter(appData.data))
{
appData.InterruptFlag = false;
}
}
break;
default:
while (1);
}
}
/*******************************************************************************
End of File
*/
I am sorry that I cannot attach the image of the output I receive in RealTerm as I do not have enough points.
I have no clue where else the problem could be that gives the mismatch of baud rate. Any hints or help would be of great help. Thanks in advance.
Kindly apologize me for any mistakes in the post.
you are correct that it is most likely BAUD rate, but just to be sure how is the USART hooked to the computer? Do you have a translator chip since the computer is expecting +-5V? As for the BAUD, check your clocking scheme and know that PBCLK is sometimes DIV_2 of the SYSCLOCK. There is a great clocking schematic in the Harmony framework to double check your clocking and CONFIG pragmas.

Arduino and Philips hue variable brightness in url

I am changing the code from a website. I removed the PIR sensor variable and added a distance sensor so i can change the brightness with my hand. I got it all figured out but i dont know how to change the brightness in the command for a variable "Brightness". Everything is local and the script works without the variable brightness.
Code for the state of the lights:
command = "{\"hue\":50100,\"sat\":255,\"bri\":255,\"transitiontime\":"+String(random(15,25))+"}";
setHue(2,command);
SetHue Method:
boolean setHue(int lightNum,String command)
{
if (client.connect(hueHubIP, hueHubPort))
{
while (client.connected())
{
client.print("PUT /api/");
client.print(hueUsername);
client.print("/lights/");
client.print(lightNum); // hueLight zero based, add 1
client.println("/state HTTP/1.1");
client.println("keep-alive");
client.print("Host: ");
client.println(hueHubIP);
client.print("Content-Length: ");
client.println(command.length());
client.println("Content-Type: text/plain;charset=UTF-8");
client.println(); // blank line before body
client.println(command); // Hue command
}
client.stop();
return true; // command executed
}
else
return false; // command failed
}
source: http://www.makeuseof.com/tag/control-philips-hue-lights-arduino-and-motion-sensor/

XBee printout, void setup()

I'm having trouble with my XBee's printing out to the monitor a simple statement, within the void setup(), as shown in my program below.
It prints the GPS and various sensor data, but it skips the whole introductory sentences. Whenever I open the arduino serial monitor, with the board plugged into my computer, it works fine.
Any suggestions? I'm at a lost!
Thanks :)
// Temperature Sensor data, Air Quality, and GPS data update XBEE
//CSV format for user interpretation
//Last updated 11/5/14
//Amy Laguna
#include <Adafruit_GPS.h>
#include <math.h>
#include <SoftwareSerial.h>
SoftwareSerial XBee(2, 3);
SoftwareSerial mySerial(8, 7);
//Read temperature sensor on A1
int tempPin = 1;
//Read CO sensor on A0
int coPin = 0;
//Read Oxygen sensor on A2
int opin = 2;
//GPS setup
Adafruit_GPS GPS(&mySerial);
//Use to debug
//SET to 'fale' to turn off echoing the GPS data to Serial
//Set to 'true' to debug and listen to raw GPS data
#define GPSECHO false
// this keeps track of whether we're using the interrupt
boolean usingInterrupt = false;
void useInterrupt(boolean);
void setup()
{
// connect at 115200 so we can read the GPS fast enough and echo without dropping chars
XBee.begin(115200);
Serial.begin(115200);
delay(5000);
XBee.println("Vehicle GPS, Temperature, and Air Quality Data!");
delay(2000);
XBee.println("Note: Elevation in Pensacola Florida: ~ 31 m (102 ft)");
XBee.println();
XBee.println("\n Date: Time: Fix: Location: Speed (mph): Elevation: CO: O2: Temperature: ");
// 9600 NMEA is the default baud rate for Adafruit MTK GPS's
GPS.begin(9600);
// RMC (recommended minimum) and GGA (fix data) including altitude
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
// Set the update rate
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
// For the parsing code to work nicely and have time to sort thru the data, and
// print it out we don't suggest using anything higher than 1 Hz
useInterrupt(true);
delay(1500);
}
// Interrupt is called once a millisecond, looks for any new GPS data, and stores it
SIGNAL(TIMER0_COMPA_vect) {
char c = GPS.read();
// if you want to debug, this is a good time to do it!
#ifdef UDR0
if (GPSECHO)
if (c) UDR0 = c;
#endif
}
void useInterrupt(boolean v) {
if (v) {
// Timer0 is already used for millis() - we'll just interrupt somewhere
// in the middle and call the "Compare A" function above
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
usingInterrupt = true;
} else {
// do not call the interrupt function COMPA anymore
TIMSK0 &= ~_BV(OCIE0A);
usingInterrupt = false;
}
}
uint32_t timer = millis();
void loop() // run over and over again
{
if (! usingInterrupt) {
// read data from the GPS in the 'main loop'
char c = GPS.read();
// if you want to debug, this is a good time to do it!
if (GPSECHO)
if (c) XBee.print(c);
}
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}
// if millis() or timer wraps around, we'll just reset it
if (timer > millis()) timer = millis();
// approximately every 2 seconds or so, print out the current stats
if (millis() - timer > 2000) {
timer = millis(); // reset the timer
PrintGPS(); //Print GPS readings
PrintAirQuality(); //Print CO and Temperature readings
}
}
void PrintGPS()
{
//Print Date, Time, Fix
XBee.print("\n");
XBee.print(GPS.month, DEC); XBee.print('/');
XBee.print(GPS.day, DEC); XBee.print("/20");
XBee.print(GPS.year, DEC);
XBee.print(" , ");
XBee.print(GPS.hour, DEC); XBee.print(':');
XBee.print(GPS.minute, DEC); XBee.print(':');
XBee.print(GPS.seconds, DEC);
}
Maybe try a longer delay before the XBee.println() statements. If the radio modules haven't associated yet, they won't be ready for you to start sending data through them.
Alternatively, wait until the first call to PrintGPS() and send it then:
void PrintGPS()
{
static int first_time = 1;
if (first_time) {
print_headers();
first_time = 0;
}
//Print Date, Time, Fix
...

SharpPCap missing packets

I'm using SharpPCap to collect IEC61850-9-2LE Sampled Values over Ethernet.
IEC61850-9-2LE Sampled Values consists of several streams, each one sending 4000 packets per second, where the avg packet size is 125 bytes.
Using SharpPCap I'm trying to collect 3 of those streams (3x4000 packets per second - 125bytes each).
In the following code I set up the Network Interface Card.
if (nicToUse != null)
{
try
{
nicToUse.OnPacketArrival -= OnPackectArrivalLive;
nicToUse.OnPacketArrival += OnPackectArrivalLive;
try
{
if (nicToUse.Started)
nicToUse.StopCapture();
if (nicToUse.Opened)
nicToUse.Close();
}
catch (Exception)
{
//no handling, just do it.
}
nicToUse.Open(OpenFlags.Promiscuous|OpenFlags.MaxResponsiveness,10);
var kernelBufferAssigned = false;
uint kernelBufferSize = 200;
while (!kernelBufferAssigned)
{
try
{
nicToUse.KernelBufferSize = kernelBufferSize * 1024 * 1024;
kernelBufferAssigned = true;
}
catch (Exception)
{
kernelBufferSize--;
}
}
nicToUse.Filter = "(ether[0:4] = 0x010CCD04)";
watchdog.Enabled = true;
counter = 0;
nicToUse.StartCapture();
}
catch (Exception ex)
{
throw new Exception(Resources.SharpPCapPacketsProducer_Start_Error_while_starting_online_capture_, ex);
}
}
This is the OnPacketArrival event handler:
private void OnPackectArrivalLive(object sender, CaptureEventArgs e)
{
try
{
counter++;
circularBuffer[circularBufferIndex] = e.Packet;
circularBufferIndex++;
if (circularBufferIndex > circularBufferSize - 1)
circularBufferIndex = 0;
}
catch (Exception)
{
}
}
When the capturing is over (user stops it), the captured packets are decoded and since they hold a sequential counter I've discovered some samples are missing.
Connecting the same source to another PC running Wireshark, those samples are not missing.
Any idea ?
What version of SharpPcap are you using? There have been some pretty big performance improvements due to overhead reduction in the 3.x and 4.x series.
Your example seems to be wrapping the circular buffer around at the tail. What type is circularBuffer? How are you sure that you are processing the packets before your buffer has filled up?
Have you looked at this example, from the SharpPcap source distribution, that shows one technique for doing background packet processing?
QueueingPacketsForBackgroundProcessing/Main.cs

Resources