Mostly Bollogs, I'm afraid

But occasionally, a glimmer of truth.
If you find one, please let me know.



Thursday, 21 August 2014

Fair

C#

namespace MVAP
{
    class Canvas : Panel
    {
        public class StateObject
        {
            // Client  socket.
            public Socket workSocket = null;
            // Size of receive buffer.
            public const int BufferSize = 1024;
            // Receive buffer.
            public byte[] buffer = new byte[BufferSize];
            // Received data string.
            public StringBuilder sb = new StringBuilder();
        }
        StateObject state;
        public int iPage;
        public static Socket sock;
        Timer t;

        int X, Y;

        public Canvas()
        {
            Y=X*2;
        }
        public void Close()
        {
            sock.Close();
        }
    }
}

1.  Q1  I want to change X on an instance of Canvas from another class inside the MVAP namespace.

Canvas canvas=new Canvas();

When I type

         canvas.

I expect intellisense to offer me canvas.X. Why doesn't it?

2.   Q2 When I change X from my other class, I want the canvas to calculate Y as X*2 automatically. How do I do that?

3.   Q3 I want a routine which opens sock and broadcasts a single character poll on it. I want the program to do nothing apart from accept user input after that, but if the equipment receiving the broadcast sends a response, I want the canvas instance to asynchronously receive it and act on it. How do I do that?




C

int i;
i=1;
int k;

switch (i)
{
         case 1:
                 int j=1;
         case 2:
                 int j=2;
         default:
                 j++;
                 k=j;
}




1.  Q4 Where are the compilation errors?

2.  Q5 Assuming I fix the compilation errors, what is j at the end of this?

3.  Q6 What is k at the end of this?



struct a {
         int i;
}

struct b {
         int i;
}

struct c {
         struct a *pa;
         struct b **ppb;
}

1 Q7   I want to make a new instance of struct c, which holds exactly one struct a and many struct b's. I want to expand this as and when required. How would I declare this and how would I add to it?

SPI


I have two PICs which need to communicate via SPI. The master needs to communicate at 2Mbps.
1.  Q8 How do I set the speed of the slave PIC?
2.  Q9 The master sends a single-character request to the slave, and reads back a single-character response dependant on the request. How do I achieve this without the master sending more than one byte?




        


No comments: