I'm trying to write a simple program which uses the GPIO pins of the Raspberry Pi 3B.
When I run the following program, only the LED on pin 17 flashes.
Pin 27 doesn't blink and doesn't get set to OUT.
I don't get any error messages.
int main(){
if (wiringPiSetupSys() == -1){
std::cout << "wiringpsetup failed\n";
exit(1);
}
auto pin = 17;
auto pin1 = 27;
pinMode(pin, OUTPUT);
pinMode(pin1, OUTPUT);
for (auto i = 0; i < 8; ++i)
{
digitalWrite(pin, HIGH);
digitalWrite(pin1, HIGH);
delay(500);
std::cout << "high\n";
digitalWrite(pin, LOW);
digitalWrite(pin1, LOW);
delay(500);
std::cout << "low\n";
}
}
However, I can make the LED on pin 27 blink by executing the following commands in the terminal:
gpio -g mode 27 out
gpio -g write 27 0
gpio -g write 27 1
gpio -g write 27 0
Consequently, the LED is properly connected and not broken.
A little additional information:
pi#raspberrypi:~$ gpio -g readall
+-----+-----+---------+------+---+---Pi 3B--+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| | | 3.3v | | | 1 || 2 | | | 5v | | |
| 2 | 8 | SDA.1 | IN | 1 | 3 || 4 | | | 5v | | |
| 3 | 9 | SCL.1 | IN | 1 | 5 || 6 | | | 0v | | |
| 4 | 7 | GPIO. 7 | IN | 1 | 7 || 8 | 0 | IN | TxD | 15 | 14 |
| | | 0v | | | 9 || 10 | 1 | IN | RxD | 16 | 15 |
| 17 | 0 | GPIO. 0 | OUT | 0 | 11 || 12 | 0 | IN | GPIO. 1 | 1 | 18 |
| 27 | 2 | GPIO. 2 | OUT | 1 | 13 || 14 | | | 0v | | |
| 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 0 | IN | GPIO. 4 | 4 | 23 |
| | | 3.3v | | | 17 || 18 | 0 | OUT | GPIO. 5 | 5 | 24 |
| 10 | 12 | MOSI | IN | 0 | 19 || 20 | | | 0v | | |
| 9 | 13 | MISO | IN | 0 | 21 || 22 | 1 | OUT | GPIO. 6 | 6 | 25 |
| 11 | 14 | SCLK | IN | 0 | 23 || 24 | 1 | IN | CE0 | 10 | 8 |
| | | 0v | | | 25 || 26 | 1 | IN | CE1 | 11 | 7 |
| 0 | 30 | SDA.0 | IN | 1 | 27 || 28 | 1 | IN | SCL.0 | 31 | 1 |
| 5 | 21 | GPIO.21 | IN | 1 | 29 || 30 | | | 0v | | |
| 6 | 22 | GPIO.22 | IN | 1 | 31 || 32 | 0 | IN | GPIO.26 | 26 | 12 |
| 13 | 23 | GPIO.23 | IN | 0 | 33 || 34 | | | 0v | | |
| 19 | 24 | GPIO.24 | IN | 0 | 35 || 36 | 0 | IN | GPIO.27 | 27 | 16 |
| 26 | 25 | GPIO.25 | IN | 0 | 37 || 38 | 0 | IN | GPIO.28 | 28 | 20 |
| | | 0v | | | 39 || 40 | 0 | IN | GPIO.29 | 29 | 21 |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+---Pi 3B--+---+------+---------+-----+-----+
I still don't know why it doesn't work in the example, but I found another solution:
Instead of wiringPiSetupSys() I use now the function wiringPiSetupPhys() and accordingly the correct pins (13 and 15).
If someone knows a solution with wiringPiSetupSys(), I would still be glad about an answer...
I have 3 tables:
table1:
Category
--------
1
2
3
4
table2:
Branch | Category
------------------
A1 | 1
A2 | 1
A3 | 2
A4 | 3
A5 | 4
A6 | 4
A7 | 4
table3: Values
Date | Branch | Value
---------------------------
1/1/2019 | A1 | 35
1/1/2019 | A2 | 40
1/1/2019 | A4 | 62
1/1/2019 | A5 | 10
1/1/2019 | A6 | 20
1/1/2019 | A7 | 35
Table Connections are:
Category -->--- Branch
and
Branch -->-- Values
I am trying to compare the value of every Branch with the average of the Category that belongs to. If the value of the Branch is below Category's average then it is good else is bad.
If I create a matrix with Branch, value and Category Average
it looks like this :
Branch | Value | Category Average
-------------------------------------
A1 | 35 | 35
A2 | 40 | 40
A4 | 62 | 62
A5 | 10 | 10
A6 | 20 | 20
A7 | 35 | 35
BranchAVG = AVERAGE(Table3[Value])
CategoryAVG = AVERAGEX(VALUES(Categories[Category]);[BranchAVG])
But it should look like this:
Branch | Value | Category Average | Good/Bad
------------------------------------------------
A1 | 35 | 37.5 | Good
A2 | 40 | 37.5 | Bad
A4 | 62 | 62.0 | Good
A5 | 10 | 21.7 | Good
A6 | 20 | 21.7 | Good
A7 | 35 | 21.7 | Bad
Is there any possible way to do that?
Thanks in advance
Elias
You can do this by adding a Category column to your Value table:
Category = RELATED(Branch[Category])
And after this add the AgeragePerCategory column:
AgeravePerCategory = CALCULATE(AVERAGE('Values'[Value]);FILTER('Values'; 'Values'[Category] = EARLIER('Values'[Category])))
Thanks for the answer.
To work it out I had to add an additional filter to Date, because it averages all values regardless the date.
So the AveragePerCategory it looks like:
AveragePerCategory = CALCULATE(AVERAGE('Values'[Value]);FILTER('Values'; 'Values'[Category] = EARLIER('Values'[Category]) && 'Values'[Date] = EARLIER('Values'[Date])))
Sample data:
| Vendor | Size Group | Model | Quantity | Cost | TAT | Posting Date |
|--------|------------|-------|----------|-------|-----|-------------------|
| A | S | A150 | 150 | 450 | 67 | July 7, 2018 |
| A | M | A200 | 250 | 1500 | 75 | June 22, 2018 |
| A | M | A150 | 25 | 8500 | 85 | July 9, 2018 |
| C | L | A200 | 350 | 1250 | 125 | March 5, 2018 |
| C | XL | A500 | 150 | 6500 | 45 | February 20, 2018 |
| A | M | A900 | 385 | 475 | 40 | January 29, 2018 |
| A | M | A150 | 650 | 45 | 45 | August 31, 2018 |
| D | M | A150 | 65 | 7500 | 15 | April 10, 2018 |
| D | M | A300 | 140 | 3420 | 10 | April 3, 2018 |
| E | S | A150 | 20 | 10525 | 85 | January 3, 2018 |
| B | S | A150 | 30 | 10500 | 40 | June 3, 2018 |
| B | S | A150 | 450 | 450 | 64 | April 3, 2018 |
| E | XS | A900 | 45 | 75 | 60 | January 3, 2018 |
| F | M | A900 | 95 | 655 | 175 | January 3, 2018 |
| D | XL | A300 | 15 | 21500 | 25 | January 3, 2018 |
| D | S | A500 | 450 | 65 | 25 | May 3, 2018 |
| A | M | A350 | 250 | 450 | 22 | January 3, 2018 |
| B | S | A150 | 45 | 8500 | 28 | January 3, 2018 |
| A | S | A300 | 550 | 650 | 128 | January 3, 2018 |
| C | M | A150 | 1500 | 855 | 190 | January 3, 2018 |
| B | M | A150 | 65 | 1750 | 41 | January 3, 2018 |
| A | L | A500 | 75 | 1700 | 24 | January 3, 2018 |
| B | S | A900 | 55 | 9800 | 37 | May 29, 2018 |
| B | M | A500 | 150 | 850 | 83 | April 18, 2018 |
In the provided sample, the common Size Groups A & B both share are S & M. So, I was hoping to display those Size Groups as the legend and Average Cost as the value in a clustered column chart.
Can anyone please advise how I can go about this?
Thank you!!!
I'm trying to sort by ID and then by Date.
What I have:
| ID | Date |
| ----------------------|
| 112 | 2013-01-01 |
| 112 | 2013-01-15 |
| 113 | 2012-01-01 |
| 112 | 2014-02-13 |
| 112 | 2013-01-02 |
| 113 | 2011-01-11 |
What I need:
| ID | Date |
| ----------------------|
| 112 | 2013-01-01 |
| 112 | 2013-01-02 |
| 112 | 2013-01-15 |
| 112 | 2014-02-13 |
| 113 | 2011-01-11 |
| 113 | 2012-01-01 |
My problem is that I only know how to sort by ID or Date.
More generally:
clear
input id foo
1 56
1 34
2 13
1 67
1 22
2 89
2 61
2 76
end
sort id (foo)
list, sepby(id)
+----------+
| id foo |
|----------|
1. | 1 22 |
2. | 1 34 |
3. | 1 56 |
4. | 1 67 |
|----------|
5. | 2 13 |
6. | 2 61 |
7. | 2 76 |
8. | 2 89 |
+----------+
In a more advanced programming context you can use the same syntax with bysort.
This problem is fixed, thanks for pointing out the mistake in declaration of the typedef.
in which i am missing _stdcall to it. After digging some materials it is something about calling conventions, somehow it treat the stack in different way. I am not really sure, but it seems fixed it. Thanks
Greetings and Hello everyone,
I am currently working on an DLL which provide Serial Port Communication and then write to the buffer the result.
Lets say the DLL function part is DLL,
and Application part be EXE.
After certain process, I will be able to create a string in DLL function.
And then i used memcpy to copy the buffer in DLL to the char* pointer the EXE provide
However, it is fine sometime with all bytes copied ,
and the EXE can dump the result just the same as the DLL has written,
but sometimes it has shown the correct values in DLL function part,
but in EXE the memory section has become gibberish.
I want to know if i am missing some obvious part, as i am not really experienced in memory and how Extern Modules works with it.
I will now post DLL part and EXE part code for your reference.
DLL Part: compiled in VC++ 2012
dumpstr : dump the first 20 bytes from the address given.
**mp_get_var is exported via a .def file and exported to a DLL**
void dumpstr(char* charC, char* desc) {
printf("\n= S T A R T ===\nDLL Dumping the %s Array...\n", desc);
int i;
for(i=0; i<20; i++) {
printf("%p:%3d | ", charC+i, *(charC+i));
if((i+1)%4==0) printf("\n");
}
printf("\n==E N D====\n");
}
int _stdcall mp_get_var(char* inSI, char* cParam, int paramIndex, char *outSI) {
//std::string returnValue = MyConvert::get_fieldvalue2(inSI,cParam, paramIndex);
printf("ON DLL START, INSI ADDR (%p)\n", inSI);
printf("ON DLL START, OUTSI ADDR (%p)\n", outSI);
dumpstr(outSI, "PREV OUTSI");
//printf("DLL received: %s\n", inSI);
//dumpstr(inSI, "THIS > INSI");
std::string returnValue = "EPTATROPICAL";
memcpy(outSI,returnValue.c_str(),returnValue.length());
//*(outSI + returnValue.length()) = '\0';
//printf("DLL copied outSI: %s\n", outSI);
dumpstr(outSI, "THIS COPIED OUTSI");
printf("ON DLL END, INSI ADDR (%p)\n", inSI);
printf("ON DLL END, OUTSI ADDR (%p)\n", outSI);
return returnValue.length();
}
EXE Part: compiled in Dev-C++
I import the library using the following statements:
and i do two request to the DLL function which respectively using Result2 and Result3 as output buffer.
typedef int (*mp_get_var)(char * , char* , int , char *);
int main() {
HINSTANCE hLib = LoadLibrary("MPComsDLL.dll");
MP_GET_VAR = (mp_get_var)GetProcAddress((HMODULE)hLib, "mp_get_var");
sprintf(cRequest, "EPAMTOH");
//using **Result2** char array for result buffer.
returnval = MP_GET_VAR(Result, cRequest, 1, Result2);
printf("ON EXE, OUTSI address : %p", Result2);
printf("%s return length: %d\n", cRequest, returnval);
dumpstr(Result2);
sprintf(cRequest, "MERCHANTID");
//using **Result3** char array for result buffer.
returnval = MP_GET_VAR(Result, cRequest, 1, Result3);
printf("ON EXE, OUTSI address : %p", Result3);
printf("%s return length: %d\n", cRequest, returnval);
dumpstr(Result3);
}
However, here is the screen dump:
For the first call
ON DLL START, INSI ADDR (0028F8B0)
ON DLL START, OUTSI ADDR (0028F680)
= S T A R T ===
DLL Dumping the PREV OUTSI Array...
0028F680: 0 | 0028F681: 0 | 0028F682: 0 | 0028F683: 0 |
0028F684: 0 | 0028F685: 0 | 0028F686: 0 | 0028F687: 0 |
0028F688: 0 | 0028F689: 0 | 0028F68A: 0 | 0028F68B: 0 |
0028F68C: 0 | 0028F68D: 0 | 0028F68E: 0 | 0028F68F: 0 |
0028F690: 0 | 0028F691: 0 | 0028F692: 0 | 0028F693: 0 |
==E N D====
= S T A R T ===
DLL Dumping the THIS COPIED OUTSI Array...
0028F680: 69 | 0028F681: 80 | 0028F682: 84 | 0028F683: 65 |
0028F684: 84 | 0028F685: 82 | 0028F686: 79 | 0028F687: 80 |
0028F688: 73 | 0028F689: 67 | 0028F68A: 65 | 0028F68B: 76 |
0028F68C: 0 | 0028F68D: 0 | 0028F68E: 0 | 0028F68F: 0 |
0028F690: 0 | 0028F691: 0 | 0028F692: 0 | 0028F693: 0 |
==E N D====
ON DLL END, INSI ADDR (0028F8B0)
ON DLL END, OUTSI ADDR (0028F680)
ON EXE, OUTSI address : 0028F680佩 return length: 12
DLL side ended for first call
Here is the dumping in EXE part for the same address.
----
Now Dumping the Char Array...
0028F680: 69 | 0028F681: 80 | 0028F682: 84 | 0028F683: 65 |
0028F684: 84 | 0028F685: 82 | 0028F686: 79 | 0028F687: 80 |
0028F688: 73 | 0028F689: 67 | 0028F68A: 65 | 0028F68B: 76 |
0028F68C: 0 | 0028F68D: 0 | 0028F68E: 0 | 0028F68F: 0 |
0028F690: 0 | 0028F691: 0 | 0028F692: 0 | 0028F693: 0 |
Dumping finish in EXE part, you can see it is the same as DLL part dump, so I assume it is working normally.
Then here it comes the next call, which use Result3 as buffer. I see it has address from 0028F450
ON DLL START, INSI ADDR (0028F8B0)
ON DLL START, OUTSI ADDR (0028F450)
= S T A R T ===
DLL Dumping the PREV OUTSI Array...
0028F450: 0 | 0028F451: 0 | 0028F452: 0 | 0028F453: 0 |
0028F454: 0 | 0028F455: 0 | 0028F456: 0 | 0028F457: 0 |
0028F458: 0 | 0028F459: 0 | 0028F45A: 0 | 0028F45B: 0 |
0028F45C: 0 | 0028F45D: 0 | 0028F45E: 0 | 0028F45F: 0 |
0028F460: 0 | 0028F461: 0 | 0028F462: 0 | 0028F463: 0 |
==E N D====
= S T A R T ===
DLL Dumping the THIS COPIED OUTSI Array...
0028F450: 69 | 0028F451: 80 | 0028F452: 84 | 0028F453: 65 |
0028F454: 84 | 0028F455: 82 | 0028F456: 79 | 0028F457: 80 |
0028F458: 73 | 0028F459: 67 | 0028F45A: 65 | 0028F45B: 76 |
0028F45C: 0 | 0028F45D: 0 | 0028F45E: 0 | 0028F45F: 0 |
0028F460: 0 | 0028F461: 0 | 0028F462: 0 | 0028F463: 0 |
==E N D====
ON DLL END, INSI ADDR (0028F8B0)
ON DLL END, OUTSI ADDR (0028F450)
ON EXE, OUTSI address : 0028F450MERCHANTID return length: 12
Strange started from here, I see in 0028F450 in DLL, it should be
69,80,84,65,84,82,79,80,73,67,65,76
However... The dump in exe become like this,
But it becomes
0,0,68,0,83,-12,40,0,0,0,0,0
The dump is here still at address 0028F450
----
Now Dumping the Char Array...
0028F450: 0 | 0028F451: 0 | 0028F452: 68 | 0028F453: 0 |
0028F454: 83 | 0028F455:-12 | 0028F456: 40 | 0028F457: 0 |
0028F458: 0 | 0028F459: 0 | 0028F45A: 0 | 0028F45B: 0 |
0028F45C: 0 | 0028F45D: 0 | 0028F45E: 0 | 0028F45F: 0 |
0028F460: 0 | 0028F461: 0 | 0028F462: 0 | 0028F463: 0 |
Just for your reference, here is the third call, with Result2 again as the buffer:
However, this hasnt been changed to gibberish mysteriously.
ON DLL START, INSI ADDR (0028F8B0)
ON DLL START, OUTSI ADDR (0028F680)
= S T A R T ===
DLL Dumping the PREV OUTSI Array...
0028F680: 69 | 0028F681: 80 | 0028F682: 84 | 0028F683: 65 |
0028F684: 84 | 0028F685: 82 | 0028F686: 79 | 0028F687: 80 |
0028F688: 73 | 0028F689: 67 | 0028F68A: 65 | 0028F68B: 76 |
0028F68C: 0 | 0028F68D: 0 | 0028F68E: 0 | 0028F68F: 0 |
0028F690: 0 | 0028F691: 0 | 0028F692: 0 | 0028F693: 0 |
==E N D====
= S T A R T ===
DLL Dumping the THIS COPIED OUTSI Array...
0028F680: 69 | 0028F681: 80 | 0028F682: 84 | 0028F683: 65 |
0028F684: 84 | 0028F685: 82 | 0028F686: 79 | 0028F687: 80 |
0028F688: 73 | 0028F689: 67 | 0028F68A: 65 | 0028F68B: 76 |
0028F68C: 0 | 0028F68D: 0 | 0028F68E: 0 | 0028F68F: 0 |
0028F690: 0 | 0028F691: 0 | 0028F692: 0 | 0028F693: 0 |
==E N D====
ON DLL END, INSI ADDR (0028F8B0)
ON DLL END, OUTSI ADDR (0028F680)
TERMINALID return length: 12
----
Now Dumping the Char Array...
0028F680: 69 | 0028F681: 80 | 0028F682: 84 | 0028F683: 65 |
0028F684: 84 | 0028F685: 82 | 0028F686: 79 | 0028F687: 80 |
0028F688: 73 | 0028F689: 67 | 0028F68A: 65 | 0028F68B: 76 |
0028F68C: 0 | 0028F68D: 0 | 0028F68E: 0 | 0028F68F: 0 |
0028F690: 0 | 0028F691: 0 | 0028F692: 0 | 0028F693: 0 |
I am confusing now and wasted a whole day on it, any further guidance is much appreciated :)
If i needed to supply more information, i would be glad to do so, thanks for your help.